From dc96e6c21ac55120cc32f130a6ad492827748f54 Mon Sep 17 00:00:00 2001 From: Sean McGrail Date: Wed, 27 Oct 2021 16:27:52 -0700 Subject: [PATCH] Regenerated Clients --- credentials/go.mod | 4 + example/service/s3/listObjects/go.mod | 4 + example/service/s3/usingPrivateLink/go.mod | 4 + feature/dynamodb/attributevalue/go.mod | 2 + feature/dynamodb/expression/go.mod | 2 + feature/dynamodbstreams/attributevalue/go.mod | 2 + .../ec2/imds/internal/configtesting/go.mod | 4 + feature/s3/manager/go.mod | 4 + internal/endpoints/v2/go.mod | 2 +- internal/endpoints/v2/go.sum | 4 +- .../protocoltest/awsrestjson/api_client.go | 37 +- .../protocoltest/awsrestjson/endpoints.go | 58 +- .../protocoltest/awsrestjson/generated.json | 2 + internal/protocoltest/awsrestjson/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- internal/protocoltest/ec2query/api_client.go | 37 +- internal/protocoltest/ec2query/endpoints.go | 58 +- internal/protocoltest/ec2query/generated.json | 2 + internal/protocoltest/ec2query/go.mod | 6 + .../ec2query/internal/endpoints/endpoints.go | 178 +++- internal/protocoltest/jsonrpc/api_client.go | 37 +- internal/protocoltest/jsonrpc/endpoints.go | 58 +- internal/protocoltest/jsonrpc/generated.json | 2 + internal/protocoltest/jsonrpc/go.mod | 6 + .../jsonrpc/internal/endpoints/endpoints.go | 178 +++- internal/protocoltest/jsonrpc10/api_client.go | 37 +- internal/protocoltest/jsonrpc10/endpoints.go | 58 +- .../protocoltest/jsonrpc10/generated.json | 2 + internal/protocoltest/jsonrpc10/go.mod | 6 + .../jsonrpc10/internal/endpoints/endpoints.go | 178 +++- internal/protocoltest/query/api_client.go | 37 +- internal/protocoltest/query/endpoints.go | 58 +- internal/protocoltest/query/generated.json | 2 + internal/protocoltest/query/go.mod | 6 + .../query/internal/endpoints/endpoints.go | 178 +++- internal/protocoltest/restxml/api_client.go | 37 +- internal/protocoltest/restxml/endpoints.go | 58 +- internal/protocoltest/restxml/generated.json | 2 + internal/protocoltest/restxml/go.mod | 6 + .../restxml/internal/endpoints/endpoints.go | 178 +++- .../restxmlwithnamespace/api_client.go | 37 +- .../restxmlwithnamespace/endpoints.go | 58 +- .../restxmlwithnamespace/generated.json | 2 + .../protocoltest/restxmlwithnamespace/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/accessanalyzer/api_client.go | 37 +- service/accessanalyzer/endpoints.go | 58 +- service/accessanalyzer/generated.json | 2 + service/accessanalyzer/go.mod | 6 + .../internal/endpoints/endpoints.go | 333 ++++++-- service/account/api_client.go | 37 +- service/account/endpoints.go | 58 +- service/account/generated.json | 2 + service/account/go.mod | 6 + .../account/internal/endpoints/endpoints.go | 186 +++- service/acm/api_client.go | 37 +- service/acm/endpoints.go | 58 +- service/acm/generated.json | 2 + service/acm/go.mod | 6 + service/acm/internal/endpoints/endpoints.go | 333 ++++++-- service/acmpca/api_client.go | 37 +- service/acmpca/endpoints.go | 58 +- service/acmpca/generated.json | 2 + service/acmpca/go.mod | 6 + .../acmpca/internal/endpoints/endpoints.go | 347 ++++++-- service/alexaforbusiness/api_client.go | 37 +- service/alexaforbusiness/endpoints.go | 58 +- service/alexaforbusiness/generated.json | 2 + service/alexaforbusiness/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- service/amp/api_client.go | 37 +- service/amp/endpoints.go | 58 +- service/amp/generated.json | 2 + service/amp/go.mod | 6 + service/amp/internal/endpoints/endpoints.go | 214 ++++- service/amplify/api_client.go | 37 +- service/amplify/endpoints.go | 58 +- service/amplify/generated.json | 2 + service/amplify/go.mod | 6 + .../amplify/internal/endpoints/endpoints.go | 254 +++++- service/amplifybackend/api_client.go | 37 +- service/amplifybackend/endpoints.go | 58 +- service/amplifybackend/generated.json | 2 + service/amplifybackend/go.mod | 6 + .../internal/endpoints/endpoints.go | 226 ++++- service/apigateway/api_client.go | 37 +- service/apigateway/endpoints.go | 58 +- service/apigateway/generated.json | 2 + service/apigateway/go.mod | 6 + .../internal/endpoints/endpoints.go | 282 +++++-- service/apigatewaymanagementapi/api_client.go | 37 +- service/apigatewaymanagementapi/endpoints.go | 58 +- .../apigatewaymanagementapi/generated.json | 2 + service/apigatewaymanagementapi/go.mod | 6 + .../internal/endpoints/endpoints.go | 258 +++++- service/apigatewayv2/api_client.go | 37 +- service/apigatewayv2/endpoints.go | 58 +- service/apigatewayv2/generated.json | 2 + service/apigatewayv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 282 +++++-- service/appconfig/api_client.go | 37 +- service/appconfig/endpoints.go | 58 +- service/appconfig/generated.json | 2 + service/appconfig/go.mod | 6 + .../appconfig/internal/endpoints/endpoints.go | 178 +++- service/appflow/api_client.go | 37 +- service/appflow/endpoints.go | 58 +- service/appflow/generated.json | 2 + service/appflow/go.mod | 6 + .../appflow/internal/endpoints/endpoints.go | 242 +++++- service/appintegrations/api_client.go | 37 +- service/appintegrations/endpoints.go | 58 +- service/appintegrations/generated.json | 2 + service/appintegrations/go.mod | 6 + .../internal/endpoints/endpoints.go | 210 ++++- service/applicationautoscaling/api_client.go | 37 +- service/applicationautoscaling/endpoints.go | 58 +- service/applicationautoscaling/generated.json | 2 + service/applicationautoscaling/go.mod | 6 + .../internal/endpoints/endpoints.go | 290 +++++-- service/applicationcostprofiler/api_client.go | 37 +- service/applicationcostprofiler/endpoints.go | 58 +- .../applicationcostprofiler/generated.json | 2 + service/applicationcostprofiler/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- .../applicationdiscoveryservice/api_client.go | 37 +- .../applicationdiscoveryservice/endpoints.go | 58 +- .../generated.json | 2 + service/applicationdiscoveryservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/applicationinsights/api_client.go | 37 +- service/applicationinsights/endpoints.go | 58 +- service/applicationinsights/generated.json | 2 + service/applicationinsights/go.mod | 6 + .../internal/endpoints/endpoints.go | 266 +++++- service/appmesh/api_client.go | 37 +- service/appmesh/endpoints.go | 58 +- service/appmesh/generated.json | 2 + service/appmesh/go.mod | 6 + .../appmesh/internal/endpoints/endpoints.go | 266 +++++- service/apprunner/api_client.go | 37 +- service/apprunner/endpoints.go | 58 +- service/apprunner/generated.json | 2 + service/apprunner/go.mod | 6 + .../apprunner/internal/endpoints/endpoints.go | 198 ++++- service/appstream/api_client.go | 37 +- service/appstream/endpoints.go | 58 +- service/appstream/generated.json | 2 + service/appstream/go.mod | 6 + .../appstream/internal/endpoints/endpoints.go | 256 +++++- service/appsync/api_client.go | 37 +- service/appsync/endpoints.go | 58 +- service/appsync/generated.json | 2 + service/appsync/go.mod | 6 + .../appsync/internal/endpoints/endpoints.go | 266 +++++- service/athena/api_client.go | 37 +- service/athena/endpoints.go | 58 +- service/athena/generated.json | 2 + service/athena/go.mod | 6 + .../athena/internal/endpoints/endpoints.go | 344 ++++++-- service/auditmanager/api_client.go | 37 +- service/auditmanager/endpoints.go | 58 +- service/auditmanager/generated.json | 2 + service/auditmanager/go.mod | 6 + .../internal/endpoints/endpoints.go | 226 ++++- service/autoscaling/api_client.go | 37 +- service/autoscaling/endpoints.go | 58 +- service/autoscaling/generated.json | 2 + service/autoscaling/go.mod | 6 + .../internal/endpoints/endpoints.go | 290 +++++-- service/autoscalingplans/api_client.go | 37 +- service/autoscalingplans/endpoints.go | 58 +- service/autoscalingplans/generated.json | 2 + service/autoscalingplans/go.mod | 6 + .../internal/endpoints/endpoints.go | 278 ++++-- service/backup/api_client.go | 37 +- service/backup/endpoints.go | 58 +- service/backup/generated.json | 2 + service/backup/go.mod | 6 + .../backup/internal/endpoints/endpoints.go | 278 ++++-- service/batch/api_client.go | 37 +- service/batch/endpoints.go | 58 +- service/batch/generated.json | 2 + service/batch/go.mod | 6 + service/batch/internal/endpoints/endpoints.go | 344 ++++++-- service/braket/api_client.go | 37 +- service/braket/endpoints.go | 58 +- service/braket/generated.json | 2 + service/braket/go.mod | 6 + .../braket/internal/endpoints/endpoints.go | 190 ++++- service/budgets/api_client.go | 37 +- service/budgets/endpoints.go | 58 +- service/budgets/generated.json | 2 + service/budgets/go.mod | 6 + .../budgets/internal/endpoints/endpoints.go | 186 +++- service/chime/api_client.go | 37 +- service/chime/endpoints.go | 58 +- service/chime/generated.json | 2 + service/chime/go.mod | 6 + service/chime/internal/endpoints/endpoints.go | 182 +++- service/chimesdkidentity/api_client.go | 37 +- service/chimesdkidentity/endpoints.go | 58 +- service/chimesdkidentity/generated.json | 2 + service/chimesdkidentity/go.mod | 6 + .../internal/endpoints/endpoints.go | 193 ++++- service/chimesdkmessaging/api_client.go | 37 +- service/chimesdkmessaging/endpoints.go | 58 +- service/chimesdkmessaging/generated.json | 2 + service/chimesdkmessaging/go.mod | 6 + .../internal/endpoints/endpoints.go | 193 ++++- service/cloud9/api_client.go | 37 +- service/cloud9/endpoints.go | 58 +- service/cloud9/generated.json | 2 + service/cloud9/go.mod | 6 + .../cloud9/internal/endpoints/endpoints.go | 262 +++++- service/cloudcontrol/api_client.go | 37 +- service/cloudcontrol/endpoints.go | 58 +- service/cloudcontrol/generated.json | 2 + service/cloudcontrol/go.mod | 6 + .../internal/endpoints/endpoints.go | 347 ++++++-- service/clouddirectory/api_client.go | 37 +- service/clouddirectory/endpoints.go | 58 +- service/clouddirectory/generated.json | 2 + service/clouddirectory/go.mod | 6 + .../internal/endpoints/endpoints.go | 218 ++++- service/cloudformation/api_client.go | 37 +- service/cloudformation/endpoints.go | 58 +- service/cloudformation/generated.json | 2 + service/cloudformation/go.mod | 6 + .../internal/endpoints/endpoints.go | 334 ++++++-- service/cloudfront/api_client.go | 37 +- service/cloudfront/endpoints.go | 58 +- service/cloudfront/generated.json | 2 + service/cloudfront/go.mod | 6 + .../internal/endpoints/endpoints.go | 186 +++- service/cloudhsm/api_client.go | 37 +- service/cloudhsm/endpoints.go | 58 +- service/cloudhsm/generated.json | 2 + service/cloudhsm/go.mod | 6 + .../cloudhsm/internal/endpoints/endpoints.go | 222 ++++- service/cloudhsmv2/api_client.go | 37 +- service/cloudhsmv2/endpoints.go | 58 +- service/cloudhsmv2/generated.json | 2 + service/cloudhsmv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 296 +++++-- service/cloudsearch/api_client.go | 37 +- service/cloudsearch/endpoints.go | 58 +- service/cloudsearch/generated.json | 2 + service/cloudsearch/go.mod | 6 + .../internal/endpoints/endpoints.go | 218 ++++- service/cloudsearchdomain/api_client.go | 37 +- service/cloudsearchdomain/endpoints.go | 58 +- service/cloudsearchdomain/generated.json | 2 + service/cloudsearchdomain/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/cloudtrail/api_client.go | 37 +- service/cloudtrail/endpoints.go | 58 +- service/cloudtrail/generated.json | 2 + service/cloudtrail/go.mod | 6 + .../internal/endpoints/endpoints.go | 330 ++++++-- service/cloudwatch/api_client.go | 37 +- service/cloudwatch/endpoints.go | 58 +- service/cloudwatch/generated.json | 2 + service/cloudwatch/go.mod | 6 + .../internal/endpoints/endpoints.go | 356 ++++++-- service/cloudwatchevents/api_client.go | 37 +- service/cloudwatchevents/endpoints.go | 58 +- service/cloudwatchevents/generated.json | 2 + service/cloudwatchevents/go.mod | 6 + .../internal/endpoints/endpoints.go | 334 ++++++-- service/cloudwatchlogs/api_client.go | 37 +- service/cloudwatchlogs/endpoints.go | 58 +- service/cloudwatchlogs/generated.json | 2 + service/cloudwatchlogs/go.mod | 6 + .../internal/endpoints/endpoints.go | 334 ++++++-- service/codeartifact/api_client.go | 37 +- service/codeartifact/endpoints.go | 58 +- service/codeartifact/generated.json | 2 + service/codeartifact/go.mod | 6 + .../internal/endpoints/endpoints.go | 230 ++++- service/codebuild/api_client.go | 37 +- service/codebuild/endpoints.go | 58 +- service/codebuild/generated.json | 2 + service/codebuild/go.mod | 6 + .../codebuild/internal/endpoints/endpoints.go | 344 ++++++-- service/codecommit/api_client.go | 37 +- service/codecommit/endpoints.go | 58 +- service/codecommit/generated.json | 2 + service/codecommit/go.mod | 6 + .../internal/endpoints/endpoints.go | 286 +++++-- service/codedeploy/api_client.go | 37 +- service/codedeploy/endpoints.go | 58 +- service/codedeploy/generated.json | 2 + service/codedeploy/go.mod | 6 + .../internal/endpoints/endpoints.go | 356 ++++++-- service/codeguruprofiler/api_client.go | 37 +- service/codeguruprofiler/endpoints.go | 58 +- service/codeguruprofiler/generated.json | 2 + service/codeguruprofiler/go.mod | 6 + .../internal/endpoints/endpoints.go | 210 ++++- service/codegurureviewer/api_client.go | 37 +- service/codegurureviewer/endpoints.go | 58 +- service/codegurureviewer/generated.json | 2 + service/codegurureviewer/go.mod | 6 + .../internal/endpoints/endpoints.go | 218 ++++- service/codepipeline/api_client.go | 37 +- service/codepipeline/endpoints.go | 58 +- service/codepipeline/generated.json | 2 + service/codepipeline/go.mod | 6 + .../internal/endpoints/endpoints.go | 320 +++++-- service/codestar/api_client.go | 37 +- service/codestar/endpoints.go | 58 +- service/codestar/generated.json | 2 + service/codestar/go.mod | 6 + .../codestar/internal/endpoints/endpoints.go | 230 ++++- service/codestarconnections/api_client.go | 37 +- service/codestarconnections/endpoints.go | 58 +- service/codestarconnections/generated.json | 2 + service/codestarconnections/go.mod | 6 + .../internal/endpoints/endpoints.go | 242 +++++- service/codestarnotifications/api_client.go | 37 +- service/codestarnotifications/endpoints.go | 58 +- service/codestarnotifications/generated.json | 2 + service/codestarnotifications/go.mod | 6 + .../internal/endpoints/endpoints.go | 234 +++++- service/cognitoidentity/api_client.go | 37 +- service/cognitoidentity/endpoints.go | 58 +- service/cognitoidentity/generated.json | 2 + service/cognitoidentity/go.mod | 6 + .../internal/endpoints/endpoints.go | 298 +++++-- service/cognitoidentityprovider/api_client.go | 37 +- service/cognitoidentityprovider/endpoints.go | 58 +- .../cognitoidentityprovider/generated.json | 2 + service/cognitoidentityprovider/go.mod | 6 + .../internal/endpoints/endpoints.go | 305 +++++-- service/cognitosync/api_client.go | 37 +- service/cognitosync/endpoints.go | 58 +- service/cognitosync/generated.json | 2 + service/cognitosync/go.mod | 6 + .../internal/endpoints/endpoints.go | 222 ++++- service/comprehend/api_client.go | 37 +- service/comprehend/endpoints.go | 58 +- service/comprehend/generated.json | 2 + service/comprehend/go.mod | 6 + .../internal/endpoints/endpoints.go | 278 +++++- service/comprehendmedical/api_client.go | 37 +- service/comprehendmedical/endpoints.go | 58 +- service/comprehendmedical/generated.json | 2 + service/comprehendmedical/go.mod | 6 + .../internal/endpoints/endpoints.go | 254 +++++- service/computeoptimizer/api_client.go | 37 +- service/computeoptimizer/endpoints.go | 58 +- service/computeoptimizer/generated.json | 2 + service/computeoptimizer/go.mod | 6 + .../internal/endpoints/endpoints.go | 326 ++++++- service/configservice/api_client.go | 37 +- service/configservice/endpoints.go | 58 +- service/configservice/generated.json | 2 + service/configservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 356 ++++++-- service/connect/api_client.go | 37 +- service/connect/endpoints.go | 58 +- service/connect/generated.json | 2 + service/connect/go.mod | 6 + .../connect/internal/endpoints/endpoints.go | 214 ++++- service/connectcontactlens/api_client.go | 37 +- service/connectcontactlens/endpoints.go | 58 +- service/connectcontactlens/generated.json | 2 + service/connectcontactlens/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/connectparticipant/api_client.go | 37 +- service/connectparticipant/endpoints.go | 58 +- service/connectparticipant/generated.json | 2 + service/connectparticipant/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- .../costandusagereportservice/api_client.go | 37 +- .../costandusagereportservice/endpoints.go | 58 +- .../costandusagereportservice/generated.json | 2 + service/costandusagereportservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 186 +++- service/costexplorer/api_client.go | 37 +- service/costexplorer/endpoints.go | 58 +- service/costexplorer/generated.json | 2 + service/costexplorer/go.mod | 6 + .../internal/endpoints/endpoints.go | 186 +++- service/customerprofiles/api_client.go | 37 +- service/customerprofiles/endpoints.go | 58 +- service/customerprofiles/generated.json | 2 + service/customerprofiles/go.mod | 6 + .../internal/endpoints/endpoints.go | 210 ++++- .../databasemigrationservice/api_client.go | 37 +- service/databasemigrationservice/endpoints.go | 58 +- .../databasemigrationservice/generated.json | 2 + service/databasemigrationservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 378 +++++++-- service/databrew/api_client.go | 37 +- service/databrew/endpoints.go | 58 +- service/databrew/generated.json | 2 + service/databrew/go.mod | 6 + .../databrew/internal/endpoints/endpoints.go | 266 +++++- service/dataexchange/api_client.go | 37 +- service/dataexchange/endpoints.go | 58 +- service/dataexchange/generated.json | 2 + service/dataexchange/go.mod | 6 + .../internal/endpoints/endpoints.go | 222 ++++- service/datapipeline/api_client.go | 37 +- service/datapipeline/endpoints.go | 58 +- service/datapipeline/generated.json | 2 + service/datapipeline/go.mod | 6 + .../internal/endpoints/endpoints.go | 202 ++++- service/datasync/api_client.go | 37 +- service/datasync/endpoints.go | 58 +- service/datasync/generated.json | 2 + service/datasync/go.mod | 6 + .../datasync/internal/endpoints/endpoints.go | 347 ++++++-- service/dax/api_client.go | 37 +- service/dax/endpoints.go | 58 +- service/dax/generated.json | 2 + service/dax/go.mod | 6 + service/dax/internal/endpoints/endpoints.go | 238 +++++- service/detective/api_client.go | 37 +- service/detective/endpoints.go | 58 +- service/detective/generated.json | 2 + service/detective/go.mod | 6 + .../detective/internal/endpoints/endpoints.go | 332 ++++++-- service/devicefarm/api_client.go | 37 +- service/devicefarm/endpoints.go | 58 +- service/devicefarm/generated.json | 2 + service/devicefarm/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- service/devopsguru/api_client.go | 37 +- service/devopsguru/endpoints.go | 58 +- service/devopsguru/generated.json | 2 + service/devopsguru/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/directconnect/api_client.go | 37 +- service/directconnect/endpoints.go | 58 +- service/directconnect/generated.json | 2 + service/directconnect/go.mod | 6 + .../internal/endpoints/endpoints.go | 334 ++++++-- service/directoryservice/api_client.go | 37 +- service/directoryservice/endpoints.go | 58 +- service/directoryservice/generated.json | 2 + service/directoryservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 363 ++++++-- service/dlm/api_client.go | 37 +- service/dlm/endpoints.go | 58 +- service/dlm/generated.json | 2 + service/dlm/go.mod | 6 + service/dlm/internal/endpoints/endpoints.go | 259 +++++- service/docdb/api_client.go | 37 +- service/docdb/endpoints.go | 58 +- service/docdb/generated.json | 2 + service/docdb/go.mod | 6 + service/docdb/internal/endpoints/endpoints.go | 413 +++++++-- service/dynamodb/api_client.go | 36 +- service/dynamodb/endpoints.go | 58 +- service/dynamodb/generated.json | 1 + service/dynamodb/go.mod | 3 + .../dynamodb/internal/endpoints/endpoints.go | 371 ++++++-- service/dynamodbstreams/api_client.go | 37 +- service/dynamodbstreams/endpoints.go | 58 +- service/dynamodbstreams/generated.json | 2 + service/dynamodbstreams/go.mod | 6 + .../internal/endpoints/endpoints.go | 374 +++++++-- service/ebs/api_client.go | 37 +- service/ebs/endpoints.go | 58 +- service/ebs/generated.json | 2 + service/ebs/go.mod | 6 + service/ebs/internal/endpoints/endpoints.go | 333 ++++++-- service/ec2/api_client.go | 37 +- service/ec2/endpoints.go | 58 +- service/ec2/generated.json | 2 + service/ec2/go.mod | 6 + service/ec2/internal/endpoints/endpoints.go | 381 +++++++-- service/ec2instanceconnect/api_client.go | 37 +- service/ec2instanceconnect/endpoints.go | 58 +- service/ec2instanceconnect/generated.json | 2 + service/ec2instanceconnect/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/ecr/api_client.go | 37 +- service/ecr/endpoints.go | 58 +- service/ecr/generated.json | 2 + service/ecr/go.mod | 6 + service/ecr/internal/endpoints/endpoints.go | 512 +++++++++-- service/ecrpublic/api_client.go | 37 +- service/ecrpublic/endpoints.go | 58 +- service/ecrpublic/generated.json | 2 + service/ecrpublic/go.mod | 6 + .../ecrpublic/internal/endpoints/endpoints.go | 188 ++++- service/ecs/api_client.go | 37 +- service/ecs/endpoints.go | 58 +- service/ecs/generated.json | 2 + service/ecs/go.mod | 6 + service/ecs/internal/endpoints/endpoints.go | 356 ++++++-- service/efs/api_client.go | 37 +- service/efs/endpoints.go | 58 +- service/efs/generated.json | 2 + service/efs/go.mod | 6 + service/efs/internal/endpoints/endpoints.go | 568 +++++++++++-- service/eks/api_client.go | 37 +- service/eks/endpoints.go | 58 +- service/eks/generated.json | 2 + service/eks/go.mod | 6 + service/eks/internal/endpoints/endpoints.go | 344 ++++++-- service/elasticache/api_client.go | 37 +- service/elasticache/endpoints.go | 58 +- service/elasticache/generated.json | 2 + service/elasticache/go.mod | 6 + .../internal/endpoints/endpoints.go | 298 +++++-- service/elasticbeanstalk/api_client.go | 37 +- service/elasticbeanstalk/endpoints.go | 58 +- service/elasticbeanstalk/generated.json | 2 + service/elasticbeanstalk/go.mod | 6 + .../internal/endpoints/endpoints.go | 322 +++++-- service/elasticinference/api_client.go | 37 +- service/elasticinference/endpoints.go | 58 +- service/elasticinference/generated.json | 2 + service/elasticinference/go.mod | 6 + .../internal/endpoints/endpoints.go | 202 ++++- service/elasticloadbalancing/api_client.go | 37 +- service/elasticloadbalancing/endpoints.go | 58 +- service/elasticloadbalancing/generated.json | 2 + service/elasticloadbalancing/go.mod | 6 + .../internal/endpoints/endpoints.go | 357 ++++++-- service/elasticloadbalancingv2/api_client.go | 37 +- service/elasticloadbalancingv2/endpoints.go | 58 +- service/elasticloadbalancingv2/generated.json | 2 + service/elasticloadbalancingv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 357 ++++++-- service/elasticsearchservice/api_client.go | 37 +- service/elasticsearchservice/endpoints.go | 58 +- service/elasticsearchservice/generated.json | 2 + service/elasticsearchservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 294 +++++-- service/elastictranscoder/api_client.go | 37 +- service/elastictranscoder/endpoints.go | 58 +- service/elastictranscoder/generated.json | 2 + service/elastictranscoder/go.mod | 6 + .../internal/endpoints/endpoints.go | 210 ++++- service/emr/api_client.go | 37 +- service/emr/endpoints.go | 58 +- service/emr/generated.json | 2 + service/emr/go.mod | 6 + service/emr/internal/endpoints/endpoints.go | 368 ++++++-- service/emrcontainers/api_client.go | 37 +- service/emrcontainers/endpoints.go | 58 +- service/emrcontainers/generated.json | 2 + service/emrcontainers/go.mod | 6 + .../internal/endpoints/endpoints.go | 305 +++++-- service/eventbridge/api_client.go | 37 +- service/eventbridge/endpoints.go | 58 +- service/eventbridge/generated.json | 2 + service/eventbridge/go.mod | 6 + .../internal/endpoints/endpoints.go | 334 ++++++-- service/finspace/api_client.go | 37 +- service/finspace/endpoints.go | 58 +- service/finspace/generated.json | 2 + service/finspace/go.mod | 6 + .../finspace/internal/endpoints/endpoints.go | 198 ++++- service/finspacedata/api_client.go | 37 +- service/finspacedata/endpoints.go | 58 +- service/finspacedata/generated.json | 2 + service/finspacedata/go.mod | 6 + .../internal/endpoints/endpoints.go | 198 ++++- service/firehose/api_client.go | 37 +- service/firehose/endpoints.go | 58 +- service/firehose/generated.json | 2 + service/firehose/go.mod | 6 + .../firehose/internal/endpoints/endpoints.go | 348 ++++++-- service/fis/api_client.go | 37 +- service/fis/endpoints.go | 58 +- service/fis/generated.json | 2 + service/fis/go.mod | 6 + service/fis/internal/endpoints/endpoints.go | 178 +++- service/fms/api_client.go | 37 +- service/fms/endpoints.go | 58 +- service/fms/generated.json | 2 + service/fms/go.mod | 6 + service/fms/internal/endpoints/endpoints.go | 509 +++++++++-- service/forecast/api_client.go | 37 +- service/forecast/endpoints.go | 58 +- service/forecast/generated.json | 2 + service/forecast/go.mod | 6 + .../forecast/internal/endpoints/endpoints.go | 251 +++++- service/forecastquery/api_client.go | 37 +- service/forecastquery/endpoints.go | 58 +- service/forecastquery/generated.json | 2 + service/forecastquery/go.mod | 6 + .../internal/endpoints/endpoints.go | 251 +++++- service/frauddetector/api_client.go | 37 +- service/frauddetector/endpoints.go | 58 +- service/frauddetector/generated.json | 2 + service/frauddetector/go.mod | 6 + .../internal/endpoints/endpoints.go | 202 ++++- service/fsx/api_client.go | 37 +- service/fsx/endpoints.go | 58 +- service/fsx/generated.json | 2 + service/fsx/go.mod | 6 + service/fsx/internal/endpoints/endpoints.go | 439 ++++++++-- service/gamelift/api_client.go | 37 +- service/gamelift/endpoints.go | 58 +- service/gamelift/generated.json | 2 + service/gamelift/go.mod | 6 + .../gamelift/internal/endpoints/endpoints.go | 266 +++++- service/glacier/api_client.go | 37 +- service/glacier/endpoints.go | 58 +- service/glacier/generated.json | 2 + service/glacier/go.mod | 6 + .../glacier/internal/endpoints/endpoints.go | 345 ++++++-- service/globalaccelerator/api_client.go | 37 +- service/globalaccelerator/endpoints.go | 58 +- service/globalaccelerator/generated.json | 2 + service/globalaccelerator/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/glue/api_client.go | 37 +- service/glue/endpoints.go | 58 +- service/glue/generated.json | 2 + service/glue/go.mod | 6 + service/glue/internal/endpoints/endpoints.go | 344 ++++++-- service/grafana/api_client.go | 37 +- service/grafana/endpoints.go | 58 +- service/grafana/generated.json | 2 + service/grafana/go.mod | 6 + .../grafana/internal/endpoints/endpoints.go | 218 ++++- service/greengrass/api_client.go | 37 +- service/greengrass/endpoints.go | 58 +- service/greengrass/generated.json | 2 + service/greengrass/go.mod | 6 + .../internal/endpoints/endpoints.go | 256 +++++- service/greengrassv2/api_client.go | 37 +- service/greengrassv2/endpoints.go | 58 +- service/greengrassv2/generated.json | 2 + service/greengrassv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 256 +++++- service/groundstation/api_client.go | 37 +- service/groundstation/endpoints.go | 58 +- service/groundstation/generated.json | 2 + service/groundstation/go.mod | 6 + .../internal/endpoints/endpoints.go | 251 +++++- service/guardduty/api_client.go | 37 +- service/guardduty/endpoints.go | 58 +- service/guardduty/generated.json | 2 + service/guardduty/go.mod | 6 + .../guardduty/internal/endpoints/endpoints.go | 344 ++++++-- service/health/api_client.go | 37 +- service/health/endpoints.go | 58 +- service/health/generated.json | 2 + service/health/go.mod | 6 + .../health/internal/endpoints/endpoints.go | 240 +++++- service/healthlake/api_client.go | 37 +- service/healthlake/endpoints.go | 58 +- service/healthlake/generated.json | 2 + service/healthlake/go.mod | 6 + .../internal/endpoints/endpoints.go | 190 ++++- service/honeycode/api_client.go | 37 +- service/honeycode/endpoints.go | 58 +- service/honeycode/generated.json | 2 + service/honeycode/go.mod | 6 + .../honeycode/internal/endpoints/endpoints.go | 182 +++- service/iam/api_client.go | 37 +- service/iam/endpoints.go | 58 +- service/iam/generated.json | 2 + service/iam/go.mod | 6 + service/iam/internal/endpoints/endpoints.go | 244 +++++- service/identitystore/api_client.go | 37 +- service/identitystore/endpoints.go | 58 +- service/identitystore/generated.json | 2 + service/identitystore/go.mod | 6 + .../internal/endpoints/endpoints.go | 245 +++++- service/imagebuilder/api_client.go | 37 +- service/imagebuilder/endpoints.go | 58 +- service/imagebuilder/generated.json | 2 + service/imagebuilder/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/inspector/api_client.go | 37 +- service/inspector/endpoints.go | 58 +- service/inspector/generated.json | 2 + service/inspector/go.mod | 6 + .../inspector/internal/endpoints/endpoints.go | 300 ++++++- service/internal/benchmark/go.mod | 2 + service/internal/integrationtest/go.mod | 2 + service/iot/api_client.go | 37 +- service/iot/endpoints.go | 58 +- service/iot/generated.json | 2 + service/iot/go.mod | 6 + service/iot/internal/endpoints/endpoints.go | 382 +++++++-- service/iot1clickdevicesservice/api_client.go | 37 +- service/iot1clickdevicesservice/endpoints.go | 58 +- .../iot1clickdevicesservice/generated.json | 2 + service/iot1clickdevicesservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 183 +++- service/iot1clickprojects/api_client.go | 37 +- service/iot1clickprojects/endpoints.go | 58 +- service/iot1clickprojects/generated.json | 2 + service/iot1clickprojects/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/iotanalytics/api_client.go | 37 +- service/iotanalytics/endpoints.go | 58 +- service/iotanalytics/generated.json | 2 + service/iotanalytics/go.mod | 6 + .../internal/endpoints/endpoints.go | 214 ++++- service/iotdataplane/api_client.go | 37 +- service/iotdataplane/endpoints.go | 58 +- service/iotdataplane/generated.json | 2 + service/iotdataplane/go.mod | 6 + .../internal/endpoints/endpoints.go | 382 +++++++-- service/iotdeviceadvisor/api_client.go | 37 +- service/iotdeviceadvisor/endpoints.go | 58 +- service/iotdeviceadvisor/generated.json | 2 + service/iotdeviceadvisor/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/iotevents/api_client.go | 37 +- service/iotevents/endpoints.go | 58 +- service/iotevents/generated.json | 2 + service/iotevents/go.mod | 6 + .../iotevents/internal/endpoints/endpoints.go | 230 ++++- service/ioteventsdata/api_client.go | 37 +- service/ioteventsdata/endpoints.go | 58 +- service/ioteventsdata/generated.json | 2 + service/ioteventsdata/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/iotfleethub/api_client.go | 37 +- service/iotfleethub/endpoints.go | 58 +- service/iotfleethub/generated.json | 2 + service/iotfleethub/go.mod | 6 + .../internal/endpoints/endpoints.go | 274 +++++- service/iotjobsdataplane/api_client.go | 37 +- service/iotjobsdataplane/endpoints.go | 58 +- service/iotjobsdataplane/generated.json | 2 + service/iotjobsdataplane/go.mod | 6 + .../internal/endpoints/endpoints.go | 343 ++++++-- service/iotsecuretunneling/api_client.go | 37 +- service/iotsecuretunneling/endpoints.go | 58 +- service/iotsecuretunneling/generated.json | 2 + service/iotsecuretunneling/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/iotsitewise/api_client.go | 37 +- service/iotsitewise/endpoints.go | 58 +- service/iotsitewise/generated.json | 2 + service/iotsitewise/go.mod | 6 + .../internal/endpoints/endpoints.go | 217 ++++- service/iotthingsgraph/api_client.go | 37 +- service/iotthingsgraph/endpoints.go | 58 +- service/iotthingsgraph/generated.json | 2 + service/iotthingsgraph/go.mod | 6 + .../internal/endpoints/endpoints.go | 215 ++++- service/iotwireless/api_client.go | 37 +- service/iotwireless/endpoints.go | 58 +- service/iotwireless/generated.json | 2 + service/iotwireless/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/ivs/api_client.go | 37 +- service/ivs/endpoints.go | 58 +- service/ivs/generated.json | 2 + service/ivs/go.mod | 6 + service/ivs/internal/endpoints/endpoints.go | 190 ++++- service/kafka/api_client.go | 37 +- service/kafka/endpoints.go | 58 +- service/kafka/generated.json | 2 + service/kafka/go.mod | 6 + service/kafka/internal/endpoints/endpoints.go | 270 ++++-- service/kafkaconnect/api_client.go | 37 +- service/kafkaconnect/endpoints.go | 58 +- service/kafkaconnect/generated.json | 2 + service/kafkaconnect/go.mod | 6 + .../internal/endpoints/endpoints.go | 242 +++++- service/kendra/api_client.go | 37 +- service/kendra/endpoints.go | 58 +- service/kendra/generated.json | 2 + service/kendra/go.mod | 6 + .../kendra/internal/endpoints/endpoints.go | 258 +++++- service/kinesis/api_client.go | 37 +- service/kinesis/endpoints.go | 58 +- service/kinesis/generated.json | 2 + service/kinesis/go.mod | 6 + .../kinesis/internal/endpoints/endpoints.go | 334 ++++++-- service/kinesisanalytics/api_client.go | 37 +- service/kinesisanalytics/endpoints.go | 58 +- service/kinesisanalytics/generated.json | 2 + service/kinesisanalytics/go.mod | 6 + .../internal/endpoints/endpoints.go | 270 ++++-- service/kinesisanalyticsv2/api_client.go | 37 +- service/kinesisanalyticsv2/endpoints.go | 58 +- service/kinesisanalyticsv2/generated.json | 2 + service/kinesisanalyticsv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 270 ++++-- service/kinesisvideo/api_client.go | 37 +- service/kinesisvideo/endpoints.go | 58 +- service/kinesisvideo/generated.json | 2 + service/kinesisvideo/go.mod | 6 + .../internal/endpoints/endpoints.go | 238 +++++- .../kinesisvideoarchivedmedia/api_client.go | 37 +- .../kinesisvideoarchivedmedia/endpoints.go | 58 +- .../kinesisvideoarchivedmedia/generated.json | 2 + service/kinesisvideoarchivedmedia/go.mod | 6 + .../internal/endpoints/endpoints.go | 238 +++++- service/kinesisvideomedia/api_client.go | 37 +- service/kinesisvideomedia/endpoints.go | 58 +- service/kinesisvideomedia/generated.json | 2 + service/kinesisvideomedia/go.mod | 6 + .../internal/endpoints/endpoints.go | 238 +++++- service/kinesisvideosignaling/api_client.go | 37 +- service/kinesisvideosignaling/endpoints.go | 58 +- service/kinesisvideosignaling/generated.json | 2 + service/kinesisvideosignaling/go.mod | 6 + .../internal/endpoints/endpoints.go | 238 +++++- service/kms/api_client.go | 37 +- service/kms/endpoints.go | 58 +- service/kms/generated.json | 2 + service/kms/go.mod | 6 + service/kms/internal/endpoints/endpoints.go | 302 +++++-- service/lakeformation/api_client.go | 37 +- service/lakeformation/endpoints.go | 58 +- service/lakeformation/generated.json | 2 + service/lakeformation/go.mod | 6 + .../internal/endpoints/endpoints.go | 329 ++++++-- service/lambda/api_client.go | 37 +- service/lambda/endpoints.go | 58 +- service/lambda/generated.json | 2 + service/lambda/go.mod | 6 + .../lambda/internal/endpoints/endpoints.go | 356 ++++++-- service/lexmodelbuildingservice/api_client.go | 37 +- service/lexmodelbuildingservice/endpoints.go | 58 +- .../lexmodelbuildingservice/generated.json | 2 + service/lexmodelbuildingservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 273 +++++- service/lexmodelsv2/api_client.go | 37 +- service/lexmodelsv2/endpoints.go | 58 +- service/lexmodelsv2/generated.json | 2 + service/lexmodelsv2/go.mod | 6 + .../internal/endpoints/endpoints.go | 222 ++++- service/lexruntimeservice/api_client.go | 37 +- service/lexruntimeservice/endpoints.go | 58 +- service/lexruntimeservice/generated.json | 2 + service/lexruntimeservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 273 +++++- service/lexruntimev2/api_client.go | 37 +- service/lexruntimev2/endpoints.go | 58 +- service/lexruntimev2/generated.json | 2 + service/lexruntimev2/go.mod | 6 + .../internal/endpoints/endpoints.go | 222 ++++- service/licensemanager/api_client.go | 37 +- service/licensemanager/endpoints.go | 58 +- service/licensemanager/generated.json | 2 + service/licensemanager/go.mod | 6 + .../internal/endpoints/endpoints.go | 352 ++++++-- service/lightsail/api_client.go | 37 +- service/lightsail/endpoints.go | 58 +- service/lightsail/generated.json | 2 + service/lightsail/go.mod | 6 + .../lightsail/internal/endpoints/endpoints.go | 234 +++++- service/location/api_client.go | 37 +- service/location/endpoints.go | 58 +- service/location/generated.json | 2 + service/location/go.mod | 6 + .../location/internal/endpoints/endpoints.go | 178 +++- service/lookoutequipment/api_client.go | 37 +- service/lookoutequipment/endpoints.go | 58 +- service/lookoutequipment/generated.json | 2 + service/lookoutequipment/go.mod | 6 + .../internal/endpoints/endpoints.go | 190 ++++- service/lookoutmetrics/api_client.go | 37 +- service/lookoutmetrics/endpoints.go | 58 +- service/lookoutmetrics/generated.json | 2 + service/lookoutmetrics/go.mod | 6 + .../internal/endpoints/endpoints.go | 207 ++++- service/lookoutvision/api_client.go | 37 +- service/lookoutvision/endpoints.go | 58 +- service/lookoutvision/generated.json | 2 + service/lookoutvision/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/machinelearning/api_client.go | 37 +- service/machinelearning/endpoints.go | 58 +- service/machinelearning/generated.json | 2 + service/machinelearning/go.mod | 6 + .../internal/endpoints/endpoints.go | 186 +++- service/macie/api_client.go | 37 +- service/macie/endpoints.go | 58 +- service/macie/generated.json | 2 + service/macie/go.mod | 6 + service/macie/internal/endpoints/endpoints.go | 208 ++++- service/macie2/api_client.go | 37 +- service/macie2/endpoints.go | 58 +- service/macie2/generated.json | 2 + service/macie2/go.mod | 6 + .../macie2/internal/endpoints/endpoints.go | 306 +++++-- service/managedblockchain/api_client.go | 37 +- service/managedblockchain/endpoints.go | 58 +- service/managedblockchain/generated.json | 2 + service/managedblockchain/go.mod | 6 + .../internal/endpoints/endpoints.go | 202 ++++- service/marketplacecatalog/api_client.go | 37 +- service/marketplacecatalog/endpoints.go | 58 +- service/marketplacecatalog/generated.json | 2 + service/marketplacecatalog/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- .../api_client.go | 37 +- .../marketplacecommerceanalytics/endpoints.go | 58 +- .../generated.json | 2 + service/marketplacecommerceanalytics/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- .../api_client.go | 37 +- .../endpoints.go | 58 +- .../generated.json | 2 + service/marketplaceentitlementservice/go.mod | 6 + .../internal/endpoints/endpoints.go | 195 ++++- service/marketplacemetering/api_client.go | 37 +- service/marketplacemetering/endpoints.go | 58 +- service/marketplacemetering/generated.json | 2 + service/marketplacemetering/go.mod | 6 + .../internal/endpoints/endpoints.go | 296 +++++-- service/mediaconnect/api_client.go | 37 +- service/mediaconnect/endpoints.go | 58 +- service/mediaconnect/generated.json | 2 + service/mediaconnect/go.mod | 6 + .../internal/endpoints/endpoints.go | 242 +++++- service/mediaconvert/api_client.go | 37 +- service/mediaconvert/endpoints.go | 58 +- service/mediaconvert/generated.json | 2 + service/mediaconvert/go.mod | 6 + .../internal/endpoints/endpoints.go | 305 +++++-- service/medialive/api_client.go | 37 +- service/medialive/endpoints.go | 58 +- service/medialive/generated.json | 2 + service/medialive/go.mod | 6 + .../medialive/internal/endpoints/endpoints.go | 271 +++++- service/mediapackage/api_client.go | 37 +- service/mediapackage/endpoints.go | 58 +- service/mediapackage/generated.json | 2 + service/mediapackage/go.mod | 6 + .../internal/endpoints/endpoints.go | 242 +++++- service/mediapackagevod/api_client.go | 37 +- service/mediapackagevod/endpoints.go | 58 +- service/mediapackagevod/generated.json | 2 + service/mediapackagevod/go.mod | 6 + .../internal/endpoints/endpoints.go | 238 +++++- service/mediastore/api_client.go | 37 +- service/mediastore/endpoints.go | 58 +- service/mediastore/generated.json | 2 + service/mediastore/go.mod | 6 + .../internal/endpoints/endpoints.go | 214 ++++- service/mediastoredata/api_client.go | 37 +- service/mediastoredata/endpoints.go | 58 +- service/mediastoredata/generated.json | 2 + service/mediastoredata/go.mod | 6 + .../internal/endpoints/endpoints.go | 214 ++++- service/mediatailor/api_client.go | 37 +- service/mediatailor/endpoints.go | 58 +- service/mediatailor/generated.json | 2 + service/mediatailor/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/memorydb/api_client.go | 37 +- service/memorydb/endpoints.go | 58 +- service/memorydb/generated.json | 2 + service/memorydb/go.mod | 6 + .../memorydb/internal/endpoints/endpoints.go | 178 +++- service/mgn/api_client.go | 37 +- service/mgn/endpoints.go | 58 +- service/mgn/generated.json | 2 + service/mgn/go.mod | 6 + service/mgn/internal/endpoints/endpoints.go | 231 ++++- service/migrationhub/api_client.go | 37 +- service/migrationhub/endpoints.go | 58 +- service/migrationhub/generated.json | 2 + service/migrationhub/go.mod | 6 + .../internal/endpoints/endpoints.go | 206 ++++- service/migrationhubconfig/api_client.go | 37 +- service/migrationhubconfig/endpoints.go | 58 +- service/migrationhubconfig/generated.json | 2 + service/migrationhubconfig/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/mobile/api_client.go | 37 +- service/mobile/endpoints.go | 58 +- service/mobile/generated.json | 2 + service/mobile/go.mod | 6 + .../mobile/internal/endpoints/endpoints.go | 178 +++- service/mq/api_client.go | 37 +- service/mq/endpoints.go | 58 +- service/mq/generated.json | 2 + service/mq/go.mod | 6 + service/mq/internal/endpoints/endpoints.go | 340 ++++++-- service/mturk/api_client.go | 37 +- service/mturk/endpoints.go | 58 +- service/mturk/generated.json | 2 + service/mturk/go.mod | 6 + service/mturk/internal/endpoints/endpoints.go | 186 +++- service/mwaa/api_client.go | 37 +- service/mwaa/endpoints.go | 58 +- service/mwaa/generated.json | 2 + service/mwaa/go.mod | 6 + service/mwaa/internal/endpoints/endpoints.go | 238 +++++- service/neptune/api_client.go | 37 +- service/neptune/endpoints.go | 58 +- service/neptune/generated.json | 2 + service/neptune/go.mod | 6 + .../neptune/internal/endpoints/endpoints.go | 413 +++++++-- service/networkfirewall/api_client.go | 37 +- service/networkfirewall/endpoints.go | 58 +- service/networkfirewall/generated.json | 2 + service/networkfirewall/go.mod | 6 + .../internal/endpoints/endpoints.go | 347 ++++++-- service/networkmanager/api_client.go | 37 +- service/networkmanager/endpoints.go | 58 +- service/networkmanager/generated.json | 2 + service/networkmanager/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/nimble/api_client.go | 37 +- service/nimble/endpoints.go | 58 +- service/nimble/generated.json | 2 + service/nimble/go.mod | 6 + .../nimble/internal/endpoints/endpoints.go | 195 ++++- service/opensearch/api_client.go | 37 +- service/opensearch/endpoints.go | 58 +- service/opensearch/generated.json | 2 + service/opensearch/go.mod | 6 + .../internal/endpoints/endpoints.go | 294 +++++-- service/opsworks/api_client.go | 37 +- service/opsworks/endpoints.go | 58 +- service/opsworks/generated.json | 2 + service/opsworks/go.mod | 6 + .../opsworks/internal/endpoints/endpoints.go | 238 +++++- service/opsworkscm/api_client.go | 37 +- service/opsworkscm/endpoints.go | 58 +- service/opsworkscm/generated.json | 2 + service/opsworkscm/go.mod | 6 + .../internal/endpoints/endpoints.go | 214 ++++- service/organizations/api_client.go | 37 +- service/organizations/endpoints.go | 58 +- service/organizations/generated.json | 2 + service/organizations/go.mod | 6 + .../internal/endpoints/endpoints.go | 218 ++++- service/outposts/api_client.go | 37 +- service/outposts/endpoints.go | 58 +- service/outposts/generated.json | 2 + service/outposts/go.mod | 6 + .../outposts/internal/endpoints/endpoints.go | 329 ++++++-- service/panorama/api_client.go | 37 +- service/panorama/endpoints.go | 58 +- service/panorama/generated.json | 2 + service/panorama/go.mod | 6 + .../panorama/internal/endpoints/endpoints.go | 178 +++- service/personalize/api_client.go | 37 +- service/personalize/endpoints.go | 58 +- service/personalize/generated.json | 2 + service/personalize/go.mod | 6 + .../internal/endpoints/endpoints.go | 226 ++++- service/personalizeevents/api_client.go | 37 +- service/personalizeevents/endpoints.go | 58 +- service/personalizeevents/generated.json | 2 + service/personalizeevents/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/personalizeruntime/api_client.go | 37 +- service/personalizeruntime/endpoints.go | 58 +- service/personalizeruntime/generated.json | 2 + service/personalizeruntime/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/pi/api_client.go | 37 +- service/pi/endpoints.go | 58 +- service/pi/generated.json | 2 + service/pi/go.mod | 6 + service/pi/internal/endpoints/endpoints.go | 251 +++++- service/pinpoint/api_client.go | 37 +- service/pinpoint/endpoints.go | 58 +- service/pinpoint/generated.json | 2 + service/pinpoint/go.mod | 6 + .../pinpoint/internal/endpoints/endpoints.go | 294 ++++++- service/pinpointemail/api_client.go | 37 +- service/pinpointemail/endpoints.go | 58 +- service/pinpointemail/generated.json | 2 + service/pinpointemail/go.mod | 6 + .../internal/endpoints/endpoints.go | 217 ++++- service/pinpointsmsvoice/api_client.go | 37 +- service/pinpointsmsvoice/endpoints.go | 58 +- service/pinpointsmsvoice/generated.json | 2 + service/pinpointsmsvoice/go.mod | 6 + .../internal/endpoints/endpoints.go | 198 ++++- service/polly/api_client.go | 37 +- service/polly/endpoints.go | 58 +- service/polly/generated.json | 2 + service/polly/go.mod | 6 + service/polly/internal/endpoints/endpoints.go | 317 +++++-- service/pricing/api_client.go | 37 +- service/pricing/endpoints.go | 58 +- service/pricing/generated.json | 2 + service/pricing/go.mod | 6 + .../pricing/internal/endpoints/endpoints.go | 199 ++++- service/proton/api_client.go | 37 +- service/proton/endpoints.go | 58 +- service/proton/generated.json | 2 + service/proton/go.mod | 6 + .../proton/internal/endpoints/endpoints.go | 178 +++- service/qldb/api_client.go | 37 +- service/qldb/endpoints.go | 58 +- service/qldb/generated.json | 2 + service/qldb/go.mod | 6 + service/qldb/internal/endpoints/endpoints.go | 251 +++++- service/qldbsession/api_client.go | 37 +- service/qldbsession/endpoints.go | 58 +- service/qldbsession/generated.json | 2 + service/qldbsession/go.mod | 6 + .../internal/endpoints/endpoints.go | 251 +++++- service/quicksight/api_client.go | 37 +- service/quicksight/endpoints.go | 58 +- service/quicksight/generated.json | 2 + service/quicksight/go.mod | 6 + .../internal/endpoints/endpoints.go | 242 +++++- service/ram/api_client.go | 37 +- service/ram/endpoints.go | 58 +- service/ram/generated.json | 2 + service/ram/go.mod | 6 + service/ram/internal/endpoints/endpoints.go | 337 ++++++-- service/rds/api_client.go | 37 +- service/rds/endpoints.go | 58 +- service/rds/generated.json | 2 + service/rds/go.mod | 6 + service/rds/internal/endpoints/endpoints.go | 413 +++++++-- service/rdsdata/api_client.go | 37 +- service/rdsdata/endpoints.go | 58 +- service/rdsdata/generated.json | 2 + service/rdsdata/go.mod | 6 + .../rdsdata/internal/endpoints/endpoints.go | 178 +++- service/redshift/api_client.go | 37 +- service/redshift/endpoints.go | 58 +- service/redshift/generated.json | 2 + service/redshift/go.mod | 6 + .../redshift/internal/endpoints/endpoints.go | 345 ++++++-- service/redshiftdata/api_client.go | 37 +- service/redshiftdata/endpoints.go | 58 +- service/redshiftdata/generated.json | 2 + service/redshiftdata/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/rekognition/api_client.go | 37 +- service/rekognition/endpoints.go | 58 +- service/rekognition/generated.json | 2 + service/rekognition/go.mod | 6 + .../internal/endpoints/endpoints.go | 372 +++++++- service/resourcegroups/api_client.go | 37 +- service/resourcegroups/endpoints.go | 58 +- service/resourcegroups/generated.json | 2 + service/resourcegroups/go.mod | 6 + .../internal/endpoints/endpoints.go | 344 ++++++-- .../resourcegroupstaggingapi/api_client.go | 37 +- service/resourcegroupstaggingapi/endpoints.go | 58 +- .../resourcegroupstaggingapi/generated.json | 2 + service/resourcegroupstaggingapi/go.mod | 6 + .../internal/endpoints/endpoints.go | 282 +++++-- service/robomaker/api_client.go | 37 +- service/robomaker/endpoints.go | 58 +- service/robomaker/generated.json | 2 + service/robomaker/go.mod | 6 + .../robomaker/internal/endpoints/endpoints.go | 206 ++++- service/route53/api_client.go | 37 +- service/route53/endpoints.go | 58 +- service/route53/generated.json | 2 + service/route53/go.mod | 6 + .../route53/internal/endpoints/endpoints.go | 226 ++++- service/route53domains/api_client.go | 37 +- service/route53domains/endpoints.go | 58 +- service/route53domains/generated.json | 2 + service/route53domains/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- service/route53recoverycluster/api_client.go | 37 +- service/route53recoverycluster/endpoints.go | 58 +- service/route53recoverycluster/generated.json | 2 + service/route53recoverycluster/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- .../api_client.go | 37 +- .../route53recoverycontrolconfig/endpoints.go | 58 +- .../generated.json | 2 + service/route53recoverycontrolconfig/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- .../route53recoveryreadiness/api_client.go | 37 +- service/route53recoveryreadiness/endpoints.go | 58 +- .../route53recoveryreadiness/generated.json | 2 + service/route53recoveryreadiness/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/route53resolver/api_client.go | 37 +- service/route53resolver/endpoints.go | 58 +- service/route53resolver/generated.json | 2 + service/route53resolver/go.mod | 6 + .../internal/endpoints/endpoints.go | 282 +++++-- service/s3/api_client.go | 43 +- service/s3/api_op_AbortMultipartUpload.go | 1 - service/s3/api_op_CompleteMultipartUpload.go | 1 - service/s3/api_op_CopyObject.go | 1 - service/s3/api_op_CreateBucket.go | 1 - service/s3/api_op_CreateMultipartUpload.go | 1 - service/s3/api_op_DeleteBucket.go | 1 - ...i_op_DeleteBucketAnalyticsConfiguration.go | 1 - service/s3/api_op_DeleteBucketCors.go | 1 - service/s3/api_op_DeleteBucketEncryption.go | 1 - ...teBucketIntelligentTieringConfiguration.go | 1 - ...i_op_DeleteBucketInventoryConfiguration.go | 1 - service/s3/api_op_DeleteBucketLifecycle.go | 1 - ...api_op_DeleteBucketMetricsConfiguration.go | 1 - .../api_op_DeleteBucketOwnershipControls.go | 1 - service/s3/api_op_DeleteBucketPolicy.go | 1 - service/s3/api_op_DeleteBucketReplication.go | 1 - service/s3/api_op_DeleteBucketTagging.go | 1 - service/s3/api_op_DeleteBucketWebsite.go | 1 - service/s3/api_op_DeleteObject.go | 1 - service/s3/api_op_DeleteObjectTagging.go | 1 - service/s3/api_op_DeleteObjects.go | 7 +- service/s3/api_op_DeletePublicAccessBlock.go | 1 - ...api_op_GetBucketAccelerateConfiguration.go | 1 - service/s3/api_op_GetBucketAcl.go | 1 - .../api_op_GetBucketAnalyticsConfiguration.go | 1 - service/s3/api_op_GetBucketCors.go | 1 - service/s3/api_op_GetBucketEncryption.go | 1 - ...etBucketIntelligentTieringConfiguration.go | 1 - .../api_op_GetBucketInventoryConfiguration.go | 1 - .../api_op_GetBucketLifecycleConfiguration.go | 1 - service/s3/api_op_GetBucketLocation.go | 1 - service/s3/api_op_GetBucketLogging.go | 1 - .../api_op_GetBucketMetricsConfiguration.go | 1 - ...i_op_GetBucketNotificationConfiguration.go | 1 - .../s3/api_op_GetBucketOwnershipControls.go | 1 - service/s3/api_op_GetBucketPolicy.go | 1 - service/s3/api_op_GetBucketPolicyStatus.go | 1 - service/s3/api_op_GetBucketReplication.go | 1 - service/s3/api_op_GetBucketRequestPayment.go | 1 - service/s3/api_op_GetBucketTagging.go | 1 - service/s3/api_op_GetBucketVersioning.go | 1 - service/s3/api_op_GetBucketWebsite.go | 1 - service/s3/api_op_GetObject.go | 1 - service/s3/api_op_GetObjectAcl.go | 1 - service/s3/api_op_GetObjectLegalHold.go | 1 - .../s3/api_op_GetObjectLockConfiguration.go | 1 - service/s3/api_op_GetObjectRetention.go | 1 - service/s3/api_op_GetObjectTagging.go | 1 - service/s3/api_op_GetObjectTorrent.go | 1 - service/s3/api_op_GetPublicAccessBlock.go | 1 - service/s3/api_op_HeadBucket.go | 1 - service/s3/api_op_HeadObject.go | 1 - ...pi_op_ListBucketAnalyticsConfigurations.go | 1 - ...tBucketIntelligentTieringConfigurations.go | 1 - ...pi_op_ListBucketInventoryConfigurations.go | 1 - .../api_op_ListBucketMetricsConfigurations.go | 1 - service/s3/api_op_ListBuckets.go | 1 - service/s3/api_op_ListMultipartUploads.go | 1 - service/s3/api_op_ListObjectVersions.go | 1 - service/s3/api_op_ListObjects.go | 1 - service/s3/api_op_ListObjectsV2.go | 1 - service/s3/api_op_ListParts.go | 1 - ...api_op_PutBucketAccelerateConfiguration.go | 1 - service/s3/api_op_PutBucketAcl.go | 7 +- .../api_op_PutBucketAnalyticsConfiguration.go | 1 - service/s3/api_op_PutBucketCors.go | 7 +- service/s3/api_op_PutBucketEncryption.go | 7 +- ...utBucketIntelligentTieringConfiguration.go | 1 - .../api_op_PutBucketInventoryConfiguration.go | 1 - .../api_op_PutBucketLifecycleConfiguration.go | 7 +- service/s3/api_op_PutBucketLogging.go | 7 +- .../api_op_PutBucketMetricsConfiguration.go | 1 - ...i_op_PutBucketNotificationConfiguration.go | 1 - .../s3/api_op_PutBucketOwnershipControls.go | 7 +- service/s3/api_op_PutBucketPolicy.go | 7 +- service/s3/api_op_PutBucketReplication.go | 7 +- service/s3/api_op_PutBucketRequestPayment.go | 7 +- service/s3/api_op_PutBucketTagging.go | 7 +- service/s3/api_op_PutBucketVersioning.go | 7 +- service/s3/api_op_PutBucketWebsite.go | 7 +- service/s3/api_op_PutObject.go | 1 - service/s3/api_op_PutObjectAcl.go | 7 +- service/s3/api_op_PutObjectLegalHold.go | 7 +- .../s3/api_op_PutObjectLockConfiguration.go | 7 +- service/s3/api_op_PutObjectRetention.go | 7 +- service/s3/api_op_PutObjectTagging.go | 7 +- service/s3/api_op_PutPublicAccessBlock.go | 7 +- service/s3/api_op_RestoreObject.go | 1 - service/s3/api_op_UploadPart.go | 1 - service/s3/api_op_UploadPartCopy.go | 1 - service/s3/api_op_WriteGetObjectResponse.go | 1 - service/s3/endpoints.go | 66 +- service/s3/generated.json | 2 + service/s3/go.mod | 6 + service/s3/internal/configtesting/go.mod | 4 + service/s3/internal/endpoints/endpoints.go | 792 +++++++++++++----- service/s3control/api_client.go | 43 +- service/s3control/api_op_CreateAccessPoint.go | 1 - ...api_op_CreateAccessPointForObjectLambda.go | 1 - service/s3control/api_op_CreateBucket.go | 7 +- service/s3control/api_op_CreateJob.go | 1 - .../api_op_CreateMultiRegionAccessPoint.go | 7 +- service/s3control/api_op_DeleteAccessPoint.go | 1 - ...api_op_DeleteAccessPointForObjectLambda.go | 1 - .../api_op_DeleteAccessPointPolicy.go | 1 - ..._DeleteAccessPointPolicyForObjectLambda.go | 1 - service/s3control/api_op_DeleteBucket.go | 1 - ...i_op_DeleteBucketLifecycleConfiguration.go | 1 - .../s3control/api_op_DeleteBucketPolicy.go | 1 - .../s3control/api_op_DeleteBucketTagging.go | 1 - service/s3control/api_op_DeleteJobTagging.go | 1 - .../api_op_DeleteMultiRegionAccessPoint.go | 7 +- .../api_op_DeletePublicAccessBlock.go | 1 - .../api_op_DeleteStorageLensConfiguration.go | 1 - ...p_DeleteStorageLensConfigurationTagging.go | 1 - service/s3control/api_op_DescribeJob.go | 1 - ...DescribeMultiRegionAccessPointOperation.go | 7 +- service/s3control/api_op_GetAccessPoint.go | 1 - ...AccessPointConfigurationForObjectLambda.go | 1 - .../api_op_GetAccessPointForObjectLambda.go | 1 - .../s3control/api_op_GetAccessPointPolicy.go | 1 - ..._op_GetAccessPointPolicyForObjectLambda.go | 1 - .../api_op_GetAccessPointPolicyStatus.go | 1 - ...tAccessPointPolicyStatusForObjectLambda.go | 1 - service/s3control/api_op_GetBucket.go | 1 - .../api_op_GetBucketLifecycleConfiguration.go | 1 - service/s3control/api_op_GetBucketPolicy.go | 1 - service/s3control/api_op_GetBucketTagging.go | 1 - service/s3control/api_op_GetJobTagging.go | 1 - .../api_op_GetMultiRegionAccessPoint.go | 7 +- .../api_op_GetMultiRegionAccessPointPolicy.go | 7 +- ...p_GetMultiRegionAccessPointPolicyStatus.go | 7 +- .../s3control/api_op_GetPublicAccessBlock.go | 1 - .../api_op_GetStorageLensConfiguration.go | 1 - ...i_op_GetStorageLensConfigurationTagging.go | 1 - service/s3control/api_op_ListAccessPoints.go | 1 - .../api_op_ListAccessPointsForObjectLambda.go | 1 - service/s3control/api_op_ListJobs.go | 1 - .../api_op_ListMultiRegionAccessPoints.go | 7 +- .../s3control/api_op_ListRegionalBuckets.go | 1 - .../api_op_ListStorageLensConfigurations.go | 1 - ...AccessPointConfigurationForObjectLambda.go | 1 - .../s3control/api_op_PutAccessPointPolicy.go | 1 - ..._op_PutAccessPointPolicyForObjectLambda.go | 1 - .../api_op_PutBucketLifecycleConfiguration.go | 7 +- service/s3control/api_op_PutBucketPolicy.go | 7 +- service/s3control/api_op_PutBucketTagging.go | 7 +- service/s3control/api_op_PutJobTagging.go | 1 - .../api_op_PutMultiRegionAccessPointPolicy.go | 7 +- .../s3control/api_op_PutPublicAccessBlock.go | 1 - .../api_op_PutStorageLensConfiguration.go | 1 - ...i_op_PutStorageLensConfigurationTagging.go | 1 - service/s3control/api_op_UpdateJobPriority.go | 1 - service/s3control/api_op_UpdateJobStatus.go | 1 - service/s3control/endpoints.go | 66 +- service/s3control/generated.json | 2 + service/s3control/go.mod | 6 + .../s3control/internal/endpoints/endpoints.go | 647 ++++++++++++-- .../internal/endpoints/s3/endpoints.go | 702 ++++++++++++---- service/s3outposts/api_client.go | 37 +- service/s3outposts/endpoints.go | 58 +- service/s3outposts/generated.json | 2 + service/s3outposts/go.mod | 6 + .../internal/endpoints/endpoints.go | 243 +++++- service/sagemaker/api_client.go | 37 +- service/sagemaker/endpoints.go | 58 +- service/sagemaker/generated.json | 2 + service/sagemaker/go.mod | 6 + .../sagemaker/internal/endpoints/endpoints.go | 356 ++++++-- service/sagemakera2iruntime/api_client.go | 37 +- service/sagemakera2iruntime/endpoints.go | 58 +- service/sagemakera2iruntime/generated.json | 2 + service/sagemakera2iruntime/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/sagemakeredge/api_client.go | 37 +- service/sagemakeredge/endpoints.go | 58 +- service/sagemakeredge/generated.json | 2 + service/sagemakeredge/go.mod | 6 + .../internal/endpoints/endpoints.go | 198 ++++- .../api_client.go | 37 +- .../sagemakerfeaturestoreruntime/endpoints.go | 58 +- .../generated.json | 2 + service/sagemakerfeaturestoreruntime/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/sagemakerruntime/api_client.go | 37 +- service/sagemakerruntime/endpoints.go | 58 +- service/sagemakerruntime/generated.json | 2 + service/sagemakerruntime/go.mod | 6 + .../internal/endpoints/endpoints.go | 333 ++++++-- service/savingsplans/api_client.go | 37 +- service/savingsplans/endpoints.go | 58 +- service/savingsplans/generated.json | 2 + service/savingsplans/go.mod | 6 + .../internal/endpoints/endpoints.go | 182 +++- service/schemas/api_client.go | 37 +- service/schemas/endpoints.go | 58 +- service/schemas/generated.json | 2 + service/schemas/go.mod | 6 + .../schemas/internal/endpoints/endpoints.go | 246 +++++- service/secretsmanager/api_client.go | 37 +- service/secretsmanager/endpoints.go | 58 +- service/secretsmanager/generated.json | 2 + service/secretsmanager/go.mod | 6 + .../internal/endpoints/endpoints.go | 348 ++++++-- service/securityhub/api_client.go | 37 +- service/securityhub/endpoints.go | 58 +- service/securityhub/generated.json | 2 + service/securityhub/go.mod | 6 + .../internal/endpoints/endpoints.go | 344 ++++++-- .../api_client.go | 37 +- .../endpoints.go | 58 +- .../generated.json | 2 + .../serverlessapplicationrepository/go.mod | 6 + .../internal/endpoints/endpoints.go | 266 +++++- service/servicecatalog/api_client.go | 37 +- service/servicecatalog/endpoints.go | 58 +- service/servicecatalog/generated.json | 2 + service/servicecatalog/go.mod | 6 + .../internal/endpoints/endpoints.go | 344 ++++++-- .../servicecatalogappregistry/api_client.go | 37 +- .../servicecatalogappregistry/endpoints.go | 58 +- .../servicecatalogappregistry/generated.json | 2 + service/servicecatalogappregistry/go.mod | 6 + .../internal/endpoints/endpoints.go | 343 ++++++-- service/servicediscovery/api_client.go | 37 +- service/servicediscovery/endpoints.go | 58 +- service/servicediscovery/generated.json | 2 + service/servicediscovery/go.mod | 6 + .../internal/endpoints/endpoints.go | 320 +++++-- service/servicequotas/api_client.go | 37 +- service/servicequotas/endpoints.go | 58 +- service/servicequotas/generated.json | 2 + service/servicequotas/go.mod | 6 + .../internal/endpoints/endpoints.go | 292 +++++-- service/ses/api_client.go | 37 +- service/ses/endpoints.go | 58 +- service/ses/generated.json | 2 + service/ses/go.mod | 6 + service/ses/internal/endpoints/endpoints.go | 217 ++++- service/sesv2/api_client.go | 37 +- service/sesv2/endpoints.go | 58 +- service/sesv2/generated.json | 2 + service/sesv2/go.mod | 6 + service/sesv2/internal/endpoints/endpoints.go | 217 ++++- service/sfn/api_client.go | 37 +- service/sfn/endpoints.go | 58 +- service/sfn/generated.json | 2 + service/sfn/go.mod | 6 + service/sfn/internal/endpoints/endpoints.go | 356 ++++++-- service/shield/api_client.go | 37 +- service/shield/endpoints.go | 58 +- service/shield/generated.json | 2 + service/shield/go.mod | 6 + .../shield/internal/endpoints/endpoints.go | 196 ++++- service/signer/api_client.go | 37 +- service/signer/endpoints.go | 58 +- service/signer/generated.json | 2 + service/signer/go.mod | 6 + .../signer/internal/endpoints/endpoints.go | 256 +++++- service/sms/api_client.go | 37 +- service/sms/endpoints.go | 58 +- service/sms/generated.json | 2 + service/sms/go.mod | 6 + service/sms/internal/endpoints/endpoints.go | 340 ++++++-- service/snowball/api_client.go | 37 +- service/snowball/endpoints.go | 58 +- service/snowball/generated.json | 2 + service/snowball/go.mod | 6 + .../snowball/internal/endpoints/endpoints.go | 502 +++++++++-- service/snowdevicemanagement/api_client.go | 37 +- service/snowdevicemanagement/endpoints.go | 58 +- service/snowdevicemanagement/generated.json | 2 + service/snowdevicemanagement/go.mod | 6 + .../internal/endpoints/endpoints.go | 192 ++++- service/sns/api_client.go | 37 +- service/sns/endpoints.go | 58 +- service/sns/generated.json | 2 + service/sns/go.mod | 6 + service/sns/internal/endpoints/endpoints.go | 334 ++++++-- service/sqs/api_client.go | 37 +- service/sqs/endpoints.go | 58 +- service/sqs/generated.json | 2 + service/sqs/go.mod | 6 + service/sqs/internal/endpoints/endpoints.go | 334 ++++++-- service/ssm/api_client.go | 37 +- service/ssm/endpoints.go | 58 +- service/ssm/generated.json | 2 + service/ssm/go.mod | 6 + service/ssm/internal/endpoints/endpoints.go | 363 ++++++-- service/ssmcontacts/api_client.go | 37 +- service/ssmcontacts/endpoints.go | 58 +- service/ssmcontacts/generated.json | 2 + service/ssmcontacts/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/ssmincidents/api_client.go | 37 +- service/ssmincidents/endpoints.go | 58 +- service/ssmincidents/generated.json | 2 + service/ssmincidents/go.mod | 6 + .../internal/endpoints/endpoints.go | 214 ++++- service/sso/api_client.go | 37 +- service/sso/endpoints.go | 58 +- service/sso/generated.json | 2 + service/sso/go.mod | 6 + service/sso/internal/endpoints/endpoints.go | 272 +++++- service/ssoadmin/api_client.go | 37 +- service/ssoadmin/endpoints.go | 58 +- service/ssoadmin/generated.json | 2 + service/ssoadmin/go.mod | 6 + .../ssoadmin/internal/endpoints/endpoints.go | 178 +++- service/ssooidc/api_client.go | 37 +- service/ssooidc/endpoints.go | 58 +- service/ssooidc/generated.json | 2 + service/ssooidc/go.mod | 6 + .../ssooidc/internal/endpoints/endpoints.go | 242 +++++- service/storagegateway/api_client.go | 37 +- service/storagegateway/endpoints.go | 58 +- service/storagegateway/generated.json | 2 + service/storagegateway/go.mod | 6 + .../internal/endpoints/endpoints.go | 286 +++++-- service/sts/api_client.go | 37 +- service/sts/endpoints.go | 58 +- service/sts/generated.json | 2 + service/sts/go.mod | 6 + service/sts/internal/endpoints/endpoints.go | 360 ++++++-- service/support/api_client.go | 37 +- service/support/endpoints.go | 58 +- service/support/generated.json | 2 + service/support/go.mod | 6 + .../support/internal/endpoints/endpoints.go | 221 ++++- service/swf/api_client.go | 37 +- service/swf/endpoints.go | 58 +- service/swf/generated.json | 2 + service/swf/go.mod | 6 + service/swf/internal/endpoints/endpoints.go | 334 ++++++-- service/synthetics/api_client.go | 37 +- service/synthetics/endpoints.go | 58 +- service/synthetics/generated.json | 2 + service/synthetics/go.mod | 6 + .../internal/endpoints/endpoints.go | 269 +++++- service/textract/api_client.go | 37 +- service/textract/endpoints.go | 58 +- service/textract/generated.json | 2 + service/textract/go.mod | 6 + .../textract/internal/endpoints/endpoints.go | 315 ++++++- service/timestreamquery/api_client.go | 36 +- service/timestreamquery/endpoints.go | 58 +- service/timestreamquery/generated.json | 1 + service/timestreamquery/go.mod | 3 + .../internal/endpoints/endpoints.go | 178 +++- service/timestreamwrite/api_client.go | 36 +- service/timestreamwrite/endpoints.go | 58 +- service/timestreamwrite/generated.json | 1 + service/timestreamwrite/go.mod | 3 + .../internal/endpoints/endpoints.go | 178 +++- service/transcribe/api_client.go | 37 +- service/transcribe/endpoints.go | 58 +- service/transcribe/generated.json | 2 + service/transcribe/go.mod | 6 + .../internal/endpoints/endpoints.go | 332 ++++++-- service/transfer/api_client.go | 37 +- service/transfer/endpoints.go | 58 +- service/transfer/generated.json | 2 + service/transfer/go.mod | 6 + .../transfer/internal/endpoints/endpoints.go | 351 ++++++-- service/translate/api_client.go | 37 +- service/translate/endpoints.go | 58 +- service/translate/generated.json | 2 + service/translate/go.mod | 6 + .../translate/internal/endpoints/endpoints.go | 294 ++++++- service/voiceid/api_client.go | 37 +- service/voiceid/endpoints.go | 58 +- service/voiceid/generated.json | 2 + service/voiceid/go.mod | 6 + .../voiceid/internal/endpoints/endpoints.go | 206 ++++- service/waf/api_client.go | 37 +- service/waf/endpoints.go | 58 +- service/waf/generated.json | 2 + service/waf/go.mod | 6 + service/waf/internal/endpoints/endpoints.go | 205 ++++- service/wafregional/api_client.go | 37 +- service/wafregional/endpoints.go | 58 +- service/wafregional/generated.json | 2 + service/wafregional/go.mod | 6 + .../internal/endpoints/endpoints.go | 628 ++++++++++++-- service/wafv2/api_client.go | 37 +- service/wafv2/endpoints.go | 58 +- service/wafv2/generated.json | 2 + service/wafv2/go.mod | 6 + service/wafv2/internal/endpoints/endpoints.go | 178 +++- service/wellarchitected/api_client.go | 37 +- service/wellarchitected/endpoints.go | 58 +- service/wellarchitected/generated.json | 2 + service/wellarchitected/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/wisdom/api_client.go | 37 +- service/wisdom/endpoints.go | 58 +- service/wisdom/generated.json | 2 + service/wisdom/go.mod | 6 + .../wisdom/internal/endpoints/endpoints.go | 198 ++++- service/workdocs/api_client.go | 37 +- service/workdocs/endpoints.go | 58 +- service/workdocs/generated.json | 2 + service/workdocs/go.mod | 6 + .../workdocs/internal/endpoints/endpoints.go | 224 ++++- service/worklink/api_client.go | 37 +- service/worklink/endpoints.go | 58 +- service/worklink/generated.json | 2 + service/worklink/go.mod | 6 + .../worklink/internal/endpoints/endpoints.go | 178 +++- service/workmail/api_client.go | 37 +- service/workmail/endpoints.go | 58 +- service/workmail/generated.json | 2 + service/workmail/go.mod | 6 + .../workmail/internal/endpoints/endpoints.go | 190 ++++- service/workmailmessageflow/api_client.go | 37 +- service/workmailmessageflow/endpoints.go | 58 +- service/workmailmessageflow/generated.json | 2 + service/workmailmessageflow/go.mod | 6 + .../internal/endpoints/endpoints.go | 178 +++- service/workspaces/api_client.go | 37 +- service/workspaces/endpoints.go | 58 +- service/workspaces/generated.json | 2 + service/workspaces/go.mod | 6 + .../internal/endpoints/endpoints.go | 271 +++++- service/xray/api_client.go | 37 +- service/xray/endpoints.go | 58 +- service/xray/generated.json | 2 + service/xray/go.mod | 6 + service/xray/internal/endpoints/endpoints.go | 344 ++++++-- 1612 files changed, 92448 insertions(+), 14867 deletions(-) diff --git a/credentials/go.mod b/credentials/go.mod index e7307266b63..41bb496a1ea 100644 --- a/credentials/go.mod +++ b/credentials/go.mod @@ -15,6 +15,10 @@ replace github.com/aws/aws-sdk-go-v2 => ../ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/sso => ../service/sso/ diff --git a/example/service/s3/listObjects/go.mod b/example/service/s3/listObjects/go.mod index 23ff4ab1459..b649fb82e12 100644 --- a/example/service/s3/listObjects/go.mod +++ b/example/service/s3/listObjects/go.mod @@ -15,6 +15,10 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/ diff --git a/example/service/s3/usingPrivateLink/go.mod b/example/service/s3/usingPrivateLink/go.mod index 68406d39898..65e9a09c506 100644 --- a/example/service/s3/usingPrivateLink/go.mod +++ b/example/service/s3/usingPrivateLink/go.mod @@ -17,6 +17,10 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/ diff --git a/feature/dynamodb/attributevalue/go.mod b/feature/dynamodb/attributevalue/go.mod index 47c0ddc991b..5a6b050b539 100644 --- a/feature/dynamodb/attributevalue/go.mod +++ b/feature/dynamodb/attributevalue/go.mod @@ -14,6 +14,8 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ diff --git a/feature/dynamodb/expression/go.mod b/feature/dynamodb/expression/go.mod index 3972127e221..7a4ce38cb5a 100644 --- a/feature/dynamodb/expression/go.mod +++ b/feature/dynamodb/expression/go.mod @@ -14,6 +14,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue => ../../.. replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ diff --git a/feature/dynamodbstreams/attributevalue/go.mod b/feature/dynamodbstreams/attributevalue/go.mod index 00e65762442..2d79422c2b0 100644 --- a/feature/dynamodbstreams/attributevalue/go.mod +++ b/feature/dynamodbstreams/attributevalue/go.mod @@ -14,6 +14,8 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ diff --git a/feature/ec2/imds/internal/configtesting/go.mod b/feature/ec2/imds/internal/configtesting/go.mod index 6fe23674f25..ae49821ca9c 100644 --- a/feature/ec2/imds/internal/configtesting/go.mod +++ b/feature/ec2/imds/internal/configtesting/go.mod @@ -15,6 +15,10 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../../service/internal/presigned-url/ diff --git a/feature/s3/manager/go.mod b/feature/s3/manager/go.mod index 86cea7aa9ea..d97a9acae86 100644 --- a/feature/s3/manager/go.mod +++ b/feature/s3/manager/go.mod @@ -18,6 +18,10 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ diff --git a/internal/endpoints/v2/go.mod b/internal/endpoints/v2/go.mod index e1308fd9755..e2628131f6f 100644 --- a/internal/endpoints/v2/go.mod +++ b/internal/endpoints/v2/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 - github.com/aws/smithy-go v1.8.0 + github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) diff --git a/internal/endpoints/v2/go.sum b/internal/endpoints/v2/go.sum index 779915f8ab7..257a75ed532 100644 --- a/internal/endpoints/v2/go.sum +++ b/internal/endpoints/v2/go.sum @@ -1,5 +1,5 @@ -github.com/aws/smithy-go v1.8.0 h1:AEwwwXQZtUwP5Mz506FeXXrKBe0jA8gVM+1gEcSRooc= -github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/aws/smithy-go v1.8.1 h1:9Y6qxtzgEODaLNGN+oN2QvcHvKUe4jsH8w4M+8LXzGk= +github.com/aws/smithy-go v1.8.1/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= diff --git a/internal/protocoltest/awsrestjson/api_client.go b/internal/protocoltest/awsrestjson/api_client.go index 8bff26f8f54..a9399f4aa2f 100644 --- a/internal/protocoltest/awsrestjson/api_client.go +++ b/internal/protocoltest/awsrestjson/api_client.go @@ -9,6 +9,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -122,6 +123,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -170,6 +173,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -198,7 +203,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -220,6 +225,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/internal/protocoltest/awsrestjson/endpoints.go b/internal/protocoltest/awsrestjson/endpoints.go index d2c3297c776..850c1bad872 100644 --- a/internal/protocoltest/awsrestjson/endpoints.go +++ b/internal/protocoltest/awsrestjson/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/awsrestjson/generated.json b/internal/protocoltest/awsrestjson/generated.json index 84fe91198de..f5d628321ff 100644 --- a/internal/protocoltest/awsrestjson/generated.json +++ b/internal/protocoltest/awsrestjson/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/awsrestjson/go.mod b/internal/protocoltest/awsrestjson/go.mod index 948e243aa97..8aeb5846b64 100644 --- a/internal/protocoltest/awsrestjson/go.mod +++ b/internal/protocoltest/awsrestjson/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/awsrestjson/internal/endpoints/endpoints.go b/internal/protocoltest/awsrestjson/internal/endpoints/endpoints.go index 957e7a6b44d..851a21c0a09 100644 --- a/internal/protocoltest/awsrestjson/internal/endpoints/endpoints.go +++ b/internal/protocoltest/awsrestjson/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Rest Json Protocol endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "restjson.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restjson.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restjson-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restjson-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restjson.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "restjson.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restjson.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restjson-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restjson-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restjson.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "restjson.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restjson.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "restjson.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restjson.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "restjson.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restjson.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restjson-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restjson-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restjson.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/ec2query/api_client.go b/internal/protocoltest/ec2query/api_client.go index 6422940f283..0578bd5c164 100644 --- a/internal/protocoltest/ec2query/api_client.go +++ b/internal/protocoltest/ec2query/api_client.go @@ -9,6 +9,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -122,6 +123,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -170,6 +173,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -198,7 +203,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -220,6 +225,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/internal/protocoltest/ec2query/endpoints.go b/internal/protocoltest/ec2query/endpoints.go index 447ffdeb812..81bf00418a9 100644 --- a/internal/protocoltest/ec2query/endpoints.go +++ b/internal/protocoltest/ec2query/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/ec2query/generated.json b/internal/protocoltest/ec2query/generated.json index 31e2f50517a..386903cb460 100644 --- a/internal/protocoltest/ec2query/generated.json +++ b/internal/protocoltest/ec2query/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/ec2query/go.mod b/internal/protocoltest/ec2query/go.mod index 1977bb6dc7b..bdd4a0b5097 100644 --- a/internal/protocoltest/ec2query/go.mod +++ b/internal/protocoltest/ec2query/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/ec2query/internal/endpoints/endpoints.go b/internal/protocoltest/ec2query/internal/endpoints/endpoints.go index fd1298187c6..e029143d113 100644 --- a/internal/protocoltest/ec2query/internal/endpoints/endpoints.go +++ b/internal/protocoltest/ec2query/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EC2 Protocol endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "awsec2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsec2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsec2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsec2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsec2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "awsec2.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsec2.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsec2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsec2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsec2.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "awsec2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "awsec2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "awsec2.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "awsec2.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "awsec2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsec2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsec2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsec2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsec2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/jsonrpc/api_client.go b/internal/protocoltest/jsonrpc/api_client.go index d996dd27ab0..88d1ee59c20 100644 --- a/internal/protocoltest/jsonrpc/api_client.go +++ b/internal/protocoltest/jsonrpc/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/internal/protocoltest/jsonrpc/endpoints.go b/internal/protocoltest/jsonrpc/endpoints.go index a681a544032..d40b1258309 100644 --- a/internal/protocoltest/jsonrpc/endpoints.go +++ b/internal/protocoltest/jsonrpc/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/jsonrpc/generated.json b/internal/protocoltest/jsonrpc/generated.json index 08499a674bc..adb76154089 100644 --- a/internal/protocoltest/jsonrpc/generated.json +++ b/internal/protocoltest/jsonrpc/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/jsonrpc/go.mod b/internal/protocoltest/jsonrpc/go.mod index a95c68be1f1..b856b2b6995 100644 --- a/internal/protocoltest/jsonrpc/go.mod +++ b/internal/protocoltest/jsonrpc/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/jsonrpc/internal/endpoints/endpoints.go b/internal/protocoltest/jsonrpc/internal/endpoints/endpoints.go index 99e00b4aed7..31638c23bc5 100644 --- a/internal/protocoltest/jsonrpc/internal/endpoints/endpoints.go +++ b/internal/protocoltest/jsonrpc/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Json Protocol endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "jsonprotocol.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonprotocol.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "jsonprotocol.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonprotocol.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "jsonprotocol.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "jsonprotocol.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "jsonprotocol.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "jsonprotocol.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "jsonprotocol.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonprotocol-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonprotocol.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/jsonrpc10/api_client.go b/internal/protocoltest/jsonrpc10/api_client.go index c0a2300c6f2..afb51cdbb69 100644 --- a/internal/protocoltest/jsonrpc10/api_client.go +++ b/internal/protocoltest/jsonrpc10/api_client.go @@ -8,6 +8,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -114,6 +115,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -162,6 +165,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -190,7 +195,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -205,6 +210,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/internal/protocoltest/jsonrpc10/endpoints.go b/internal/protocoltest/jsonrpc10/endpoints.go index 13f9c42ff86..6c32cb591eb 100644 --- a/internal/protocoltest/jsonrpc10/endpoints.go +++ b/internal/protocoltest/jsonrpc10/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/jsonrpc10/generated.json b/internal/protocoltest/jsonrpc10/generated.json index c00d3903dd4..fa241676af8 100644 --- a/internal/protocoltest/jsonrpc10/generated.json +++ b/internal/protocoltest/jsonrpc10/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/jsonrpc10/go.mod b/internal/protocoltest/jsonrpc10/go.mod index 4cc44ac0a4c..89582e4846e 100644 --- a/internal/protocoltest/jsonrpc10/go.mod +++ b/internal/protocoltest/jsonrpc10/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/jsonrpc10/internal/endpoints/endpoints.go b/internal/protocoltest/jsonrpc10/internal/endpoints/endpoints.go index 1b325caf10a..c086736977a 100644 --- a/internal/protocoltest/jsonrpc10/internal/endpoints/endpoints.go +++ b/internal/protocoltest/jsonrpc10/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver JSON RPC 10 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "jsonrpc10.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonrpc10.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "jsonrpc10.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonrpc10.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "jsonrpc10.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "jsonrpc10.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "jsonrpc10.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "jsonrpc10.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "jsonrpc10.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "jsonrpc10-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "jsonrpc10.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/query/api_client.go b/internal/protocoltest/query/api_client.go index 604fb2fc636..d7fd965f9f0 100644 --- a/internal/protocoltest/query/api_client.go +++ b/internal/protocoltest/query/api_client.go @@ -9,6 +9,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -122,6 +123,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -170,6 +173,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -198,7 +203,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -220,6 +225,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/internal/protocoltest/query/endpoints.go b/internal/protocoltest/query/endpoints.go index b9c2d645db8..f23f3ce4d0d 100644 --- a/internal/protocoltest/query/endpoints.go +++ b/internal/protocoltest/query/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/query/generated.json b/internal/protocoltest/query/generated.json index ae81eb67b1d..d445a0ffb27 100644 --- a/internal/protocoltest/query/generated.json +++ b/internal/protocoltest/query/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/query/go.mod b/internal/protocoltest/query/go.mod index 3d5da6c5b4c..e73b907cf4a 100644 --- a/internal/protocoltest/query/go.mod +++ b/internal/protocoltest/query/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/query/internal/endpoints/endpoints.go b/internal/protocoltest/query/internal/endpoints/endpoints.go index a49ff1e248f..731385e8cca 100644 --- a/internal/protocoltest/query/internal/endpoints/endpoints.go +++ b/internal/protocoltest/query/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Query Protocol endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "awsquery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsquery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsquery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsquery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsquery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "awsquery.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsquery.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsquery-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsquery-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsquery.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "awsquery.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "awsquery.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "awsquery.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "awsquery.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "awsquery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "awsquery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "awsquery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "awsquery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "awsquery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/restxml/api_client.go b/internal/protocoltest/restxml/api_client.go index 10108c36982..36d1c8c4736 100644 --- a/internal/protocoltest/restxml/api_client.go +++ b/internal/protocoltest/restxml/api_client.go @@ -9,6 +9,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -122,6 +123,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -170,6 +173,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -198,7 +203,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -220,6 +225,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/internal/protocoltest/restxml/endpoints.go b/internal/protocoltest/restxml/endpoints.go index 6084b8e6f25..abce273877d 100644 --- a/internal/protocoltest/restxml/endpoints.go +++ b/internal/protocoltest/restxml/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/restxml/generated.json b/internal/protocoltest/restxml/generated.json index 81f93f7db68..954de284e6e 100644 --- a/internal/protocoltest/restxml/generated.json +++ b/internal/protocoltest/restxml/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/restxml/go.mod b/internal/protocoltest/restxml/go.mod index 583c00ca3a4..d0180c85ea4 100644 --- a/internal/protocoltest/restxml/go.mod +++ b/internal/protocoltest/restxml/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/restxml/internal/endpoints/endpoints.go b/internal/protocoltest/restxml/internal/endpoints/endpoints.go index 46d9ed631bc..e0524906222 100644 --- a/internal/protocoltest/restxml/internal/endpoints/endpoints.go +++ b/internal/protocoltest/restxml/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Rest Xml Protocol endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "restxml.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxml.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxml-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxml-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxml.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "restxml.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxml.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxml-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxml-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxml.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "restxml.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restxml.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "restxml.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restxml.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "restxml.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxml.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxml-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxml-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxml.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/internal/protocoltest/restxmlwithnamespace/api_client.go b/internal/protocoltest/restxmlwithnamespace/api_client.go index 8aca63d43f2..312edd3b212 100644 --- a/internal/protocoltest/restxmlwithnamespace/api_client.go +++ b/internal/protocoltest/restxmlwithnamespace/api_client.go @@ -8,6 +8,7 @@ import ( awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -114,6 +115,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -162,6 +165,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -190,7 +195,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -205,6 +210,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/internal/protocoltest/restxmlwithnamespace/endpoints.go b/internal/protocoltest/restxmlwithnamespace/endpoints.go index 887eeb3e4f5..a41299b18d1 100644 --- a/internal/protocoltest/restxmlwithnamespace/endpoints.go +++ b/internal/protocoltest/restxmlwithnamespace/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/internal/protocoltest/restxmlwithnamespace/generated.json b/internal/protocoltest/restxmlwithnamespace/generated.json index ae698ac61da..ec739280ba0 100644 --- a/internal/protocoltest/restxmlwithnamespace/generated.json +++ b/internal/protocoltest/restxmlwithnamespace/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/google/go-cmp": "v0.5.4" }, diff --git a/internal/protocoltest/restxmlwithnamespace/go.mod b/internal/protocoltest/restxmlwithnamespace/go.mod index e29b765bc03..e80353ff149 100644 --- a/internal/protocoltest/restxmlwithnamespace/go.mod +++ b/internal/protocoltest/restxmlwithnamespace/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/google/go-cmp v0.5.6 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ diff --git a/internal/protocoltest/restxmlwithnamespace/internal/endpoints/endpoints.go b/internal/protocoltest/restxmlwithnamespace/internal/endpoints/endpoints.go index 10a0a12d8d2..57406e4e3fe 100644 --- a/internal/protocoltest/restxmlwithnamespace/internal/endpoints/endpoints.go +++ b/internal/protocoltest/restxmlwithnamespace/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Rest Xml Protocol Namespace endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "restxmlwithnamespace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxmlwithnamespace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "restxmlwithnamespace.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxmlwithnamespace.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "restxmlwithnamespace.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restxmlwithnamespace.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "restxmlwithnamespace.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "restxmlwithnamespace.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "restxmlwithnamespace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "restxmlwithnamespace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "restxmlwithnamespace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/accessanalyzer/api_client.go b/service/accessanalyzer/api_client.go index 2519d492f6f..a25b131e9a6 100644 --- a/service/accessanalyzer/api_client.go +++ b/service/accessanalyzer/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/accessanalyzer/endpoints.go b/service/accessanalyzer/endpoints.go index 0f3ea2ad96c..0c7bb1bca8a 100644 --- a/service/accessanalyzer/endpoints.go +++ b/service/accessanalyzer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/accessanalyzer/generated.json b/service/accessanalyzer/generated.json index 9930250adb5..98a217c162a 100644 --- a/service/accessanalyzer/generated.json +++ b/service/accessanalyzer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/accessanalyzer/go.mod b/service/accessanalyzer/go.mod index 605fb8ed4b0..e5fcca1b245 100644 --- a/service/accessanalyzer/go.mod +++ b/service/accessanalyzer/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/accessanalyzer/internal/endpoints/endpoints.go b/service/accessanalyzer/internal/endpoints/endpoints.go index 7ef03239c31..de3b14bd1ed 100644 --- a/service/accessanalyzer/internal/endpoints/endpoints.go +++ b/service/accessanalyzer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AccessAnalyzer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,296 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "access-analyzer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "access-analyzer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "access-analyzer-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "access-analyzer-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "access-analyzer-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "access-analyzer-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "access-analyzer-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "access-analyzer.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "access-analyzer.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "access-analyzer.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "access-analyzer.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "access-analyzer.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "access-analyzer.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "access-analyzer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "access-analyzer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "access-analyzer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "access-analyzer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "access-analyzer.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "access-analyzer.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/account/api_client.go b/service/account/api_client.go index a43d83f886e..c1da446a771 100644 --- a/service/account/api_client.go +++ b/service/account/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/account/endpoints.go b/service/account/endpoints.go index 476301d0bb7..ac4acae4737 100644 --- a/service/account/endpoints.go +++ b/service/account/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/account/generated.json b/service/account/generated.json index 8d2872d0619..263341ba738 100644 --- a/service/account/generated.json +++ b/service/account/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/account/go.mod b/service/account/go.mod index 59810329346..c9bfda8d4e8 100644 --- a/service/account/go.mod +++ b/service/account/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/account/internal/endpoints/endpoints.go b/service/account/internal/endpoints/endpoints.go index 37c61f2885f..662794d2496 100644 --- a/service/account/internal/endpoints/endpoints.go +++ b/service/account/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Account endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "account.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "account.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "account-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "account-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "account.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "account.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -74,16 +148,43 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "account.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "account.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "account-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "account-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "account.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "account.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -93,30 +194,63 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "account.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "account.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "account.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "account.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "account.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "account.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "account-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "account-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "account.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/acm/api_client.go b/service/acm/api_client.go index 5712b583fb2..1d56a002669 100644 --- a/service/acm/api_client.go +++ b/service/acm/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/acm/endpoints.go b/service/acm/endpoints.go index 4ed1e2f5cb2..ed186dd09d6 100644 --- a/service/acm/endpoints.go +++ b/service/acm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/acm/generated.json b/service/acm/generated.json index 3d6d58d5bd4..c15389bff81 100644 --- a/service/acm/generated.json +++ b/service/acm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/acm/go.mod b/service/acm/go.mod index 9c0747673fd..66df42e322d 100644 --- a/service/acm/go.mod +++ b/service/acm/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/acm/internal/endpoints/endpoints.go b/service/acm/internal/endpoints/endpoints.go index 669a9ee2194..98d93fde2fa 100644 --- a/service/acm/internal/endpoints/endpoints.go +++ b/service/acm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ACM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,296 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "acm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "ca-central-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1-fips", + }: endpoints.Endpoint{ Hostname: "acm-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "acm-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "acm-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.us-west-1.amazonaws.com", }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "acm-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.us-west-2.amazonaws.com", }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "acm-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "acm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "acm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "acm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "acm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "acm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "acm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "acm.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "acm.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/acmpca/api_client.go b/service/acmpca/api_client.go index a44948d9b57..b1c4b77ca2e 100644 --- a/service/acmpca/api_client.go +++ b/service/acmpca/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/acmpca/endpoints.go b/service/acmpca/endpoints.go index 4afd6ea3f4f..00a4064d839 100644 --- a/service/acmpca/endpoints.go +++ b/service/acmpca/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/acmpca/generated.json b/service/acmpca/generated.json index 87c96e4398e..68a17ab11ae 100644 --- a/service/acmpca/generated.json +++ b/service/acmpca/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/acmpca/go.mod b/service/acmpca/go.mod index a7631ced3be..77b94316ee4 100644 --- a/service/acmpca/go.mod +++ b/service/acmpca/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/acmpca/internal/endpoints/endpoints.go b/service/acmpca/internal/endpoints/endpoints.go index f8c44171039..dce9f9cf7f1 100644 --- a/service/acmpca/internal/endpoints/endpoints.go +++ b/service/acmpca/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ACM PCA endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,313 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "acm-pca.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm-pca.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-pca-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm-pca.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "acm-pca-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "acm-pca-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "acm-pca-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "acm-pca-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "acm-pca-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "acm-pca.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm-pca.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-pca-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm-pca.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "acm-pca.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "acm-pca.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "acm-pca.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "acm-pca.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "acm-pca.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "acm-pca.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "acm-pca-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "acm-pca.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "acm-pca.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "acm-pca.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "acm-pca.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/alexaforbusiness/api_client.go b/service/alexaforbusiness/api_client.go index 5f63cf9134c..6b96eddf798 100644 --- a/service/alexaforbusiness/api_client.go +++ b/service/alexaforbusiness/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/alexaforbusiness/endpoints.go b/service/alexaforbusiness/endpoints.go index c01599219f7..7679d043e04 100644 --- a/service/alexaforbusiness/endpoints.go +++ b/service/alexaforbusiness/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/alexaforbusiness/generated.json b/service/alexaforbusiness/generated.json index faf886cfcd6..0b5549589ab 100644 --- a/service/alexaforbusiness/generated.json +++ b/service/alexaforbusiness/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/alexaforbusiness/go.mod b/service/alexaforbusiness/go.mod index 75f97247d7c..45e3a9e35f3 100644 --- a/service/alexaforbusiness/go.mod +++ b/service/alexaforbusiness/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/alexaforbusiness/internal/endpoints/endpoints.go b/service/alexaforbusiness/internal/endpoints/endpoints.go index 9cacd85168b..f5b47021d49 100644 --- a/service/alexaforbusiness/internal/endpoints/endpoints.go +++ b/service/alexaforbusiness/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Alexa For Business endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,53 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "a4b.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a4b.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a4b-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a4b-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a4b.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "a4b.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a4b.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a4b-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a4b-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a4b.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "a4b.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "a4b.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "a4b.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "a4b.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "a4b.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a4b.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a4b-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a4b-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a4b.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/amp/api_client.go b/service/amp/api_client.go index 3b2d4485204..bfee2383a66 100644 --- a/service/amp/api_client.go +++ b/service/amp/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/amp/endpoints.go b/service/amp/endpoints.go index c4ec6cc47a2..3d3ee3051cf 100644 --- a/service/amp/endpoints.go +++ b/service/amp/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/amp/generated.json b/service/amp/generated.json index 0dc2c0242b5..921ca952e70 100644 --- a/service/amp/generated.json +++ b/service/amp/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/amp/go.mod b/service/amp/go.mod index 011eceb0970..4d7e4c1bd05 100644 --- a/service/amp/go.mod +++ b/service/amp/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/amp/internal/endpoints/endpoints.go b/service/amp/internal/endpoints/endpoints.go index 35ed51afdf3..007f9f0eaf0 100644 --- a/service/amp/internal/endpoints/endpoints.go +++ b/service/amp/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver amp endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "aps.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "aps.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "aps-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "aps-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "aps.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "aps.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "aps.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "aps-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "aps-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "aps.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "aps.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "aps.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "aps.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "aps.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "aps.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "aps.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "aps-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "aps-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "aps.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/amplify/api_client.go b/service/amplify/api_client.go index 6151f975df7..1baef1d6b8b 100644 --- a/service/amplify/api_client.go +++ b/service/amplify/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/amplify/endpoints.go b/service/amplify/endpoints.go index 564b04aecd7..d798d766b69 100644 --- a/service/amplify/endpoints.go +++ b/service/amplify/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/amplify/generated.json b/service/amplify/generated.json index 555eba53074..40796be946d 100644 --- a/service/amplify/generated.json +++ b/service/amplify/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/amplify/go.mod b/service/amplify/go.mod index 4d8fb0678e6..17c24d60abe 100644 --- a/service/amplify/go.mod +++ b/service/amplify/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/amplify/internal/endpoints/endpoints.go b/service/amplify/internal/endpoints/endpoints.go index b52bcff9eea..8b1519d4e58 100644 --- a/service/amplify/internal/endpoints/endpoints.go +++ b/service/amplify/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Amplify endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,71 +102,192 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "amplify.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplify.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplify-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplify-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplify.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "amplify.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplify.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplify-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplify-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplify.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "amplify.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "amplify.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "amplify.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "amplify.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "amplify.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplify.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplify-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplify-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplify.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/amplifybackend/api_client.go b/service/amplifybackend/api_client.go index a3566e02328..94ab425c358 100644 --- a/service/amplifybackend/api_client.go +++ b/service/amplifybackend/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/amplifybackend/endpoints.go b/service/amplifybackend/endpoints.go index 36504d6e4cc..5ecfaf2ec41 100644 --- a/service/amplifybackend/endpoints.go +++ b/service/amplifybackend/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/amplifybackend/generated.json b/service/amplifybackend/generated.json index 1fd187c4653..36e6b02d305 100644 --- a/service/amplifybackend/generated.json +++ b/service/amplifybackend/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/amplifybackend/go.mod b/service/amplifybackend/go.mod index c6a76edd6f8..d0bbcdba01b 100644 --- a/service/amplifybackend/go.mod +++ b/service/amplifybackend/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/amplifybackend/internal/endpoints/endpoints.go b/service/amplifybackend/internal/endpoints/endpoints.go index 6a7e2783f15..5d4bd0e7d0f 100644 --- a/service/amplifybackend/internal/endpoints/endpoints.go +++ b/service/amplifybackend/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AmplifyBackend endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,64 +102,171 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "amplifybackend.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplifybackend-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplifybackend.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "amplifybackend.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplifybackend-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplifybackend.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "amplifybackend.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "amplifybackend.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "amplifybackend.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "amplifybackend.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "amplifybackend.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "amplifybackend-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "amplifybackend-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "amplifybackend.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/apigateway/api_client.go b/service/apigateway/api_client.go index 8ee1564a3ff..6bd7685a5a2 100644 --- a/service/apigateway/api_client.go +++ b/service/apigateway/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" agcust "github.com/aws/aws-sdk-go-v2/service/apigateway/internal/customizations" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/apigateway/endpoints.go b/service/apigateway/endpoints.go index 4242a22d0c7..58571c57457 100644 --- a/service/apigateway/endpoints.go +++ b/service/apigateway/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/apigateway/generated.json b/service/apigateway/generated.json index 089e853c169..d56c5b3f3a6 100644 --- a/service/apigateway/generated.json +++ b/service/apigateway/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/apigateway/go.mod b/service/apigateway/go.mod index 38a16c48666..e73cc521d40 100644 --- a/service/apigateway/go.mod +++ b/service/apigateway/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/apigateway/internal/endpoints/endpoints.go b/service/apigateway/internal/endpoints/endpoints.go index ec6be94b1b1..7110627e3cb 100644 --- a/service/apigateway/internal/endpoints/endpoints.go +++ b/service/apigateway/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver API Gateway endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,86 +102,221 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/apigatewaymanagementapi/api_client.go b/service/apigatewaymanagementapi/api_client.go index 859b9a28eec..d64539191c0 100644 --- a/service/apigatewaymanagementapi/api_client.go +++ b/service/apigatewaymanagementapi/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/apigatewaymanagementapi/endpoints.go b/service/apigatewaymanagementapi/endpoints.go index 9ffce519777..2995dae0d39 100644 --- a/service/apigatewaymanagementapi/endpoints.go +++ b/service/apigatewaymanagementapi/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/apigatewaymanagementapi/generated.json b/service/apigatewaymanagementapi/generated.json index 2bc3136f431..f7dfc100d13 100644 --- a/service/apigatewaymanagementapi/generated.json +++ b/service/apigatewaymanagementapi/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/apigatewaymanagementapi/go.mod b/service/apigatewaymanagementapi/go.mod index d0d098353d4..b047fee2313 100644 --- a/service/apigatewaymanagementapi/go.mod +++ b/service/apigatewaymanagementapi/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/apigatewaymanagementapi/internal/endpoints/endpoints.go b/service/apigatewaymanagementapi/internal/endpoints/endpoints.go index d4b72e45edc..19df3001fb3 100644 --- a/service/apigatewaymanagementapi/internal/endpoints/endpoints.go +++ b/service/apigatewaymanagementapi/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ApiGatewayManagementApi endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,215 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "execute-api.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "execute-api.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "execute-api-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "execute-api-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "execute-api.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "execute-api.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "execute-api.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "execute-api-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "execute-api-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "execute-api.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "execute-api.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "execute-api.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "execute-api.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "execute-api.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "execute-api.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "execute-api.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "execute-api-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "execute-api-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "execute-api.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + }, }, } diff --git a/service/apigatewayv2/api_client.go b/service/apigatewayv2/api_client.go index c4e29dc430d..843bec62823 100644 --- a/service/apigatewayv2/api_client.go +++ b/service/apigatewayv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/apigatewayv2/endpoints.go b/service/apigatewayv2/endpoints.go index a5fa9d0eaed..a95b3880ea6 100644 --- a/service/apigatewayv2/endpoints.go +++ b/service/apigatewayv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/apigatewayv2/generated.json b/service/apigatewayv2/generated.json index 73b967b7586..5067c16ae9d 100644 --- a/service/apigatewayv2/generated.json +++ b/service/apigatewayv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/apigatewayv2/go.mod b/service/apigatewayv2/go.mod index 448b90b39dc..ebd20ad253c 100644 --- a/service/apigatewayv2/go.mod +++ b/service/apigatewayv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/apigatewayv2/internal/endpoints/endpoints.go b/service/apigatewayv2/internal/endpoints/endpoints.go index 25a2bead9db..b38614c42c1 100644 --- a/service/apigatewayv2/internal/endpoints/endpoints.go +++ b/service/apigatewayv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ApiGatewayV2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,86 +102,221 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "apigateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apigateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apigateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apigateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apigateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/appconfig/api_client.go b/service/appconfig/api_client.go index d64ef07d67b..af2882578e7 100644 --- a/service/appconfig/api_client.go +++ b/service/appconfig/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/appconfig/endpoints.go b/service/appconfig/endpoints.go index 888d8f2912c..84e51520e94 100644 --- a/service/appconfig/endpoints.go +++ b/service/appconfig/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appconfig/generated.json b/service/appconfig/generated.json index e25e7008baf..396e5b14ecc 100644 --- a/service/appconfig/generated.json +++ b/service/appconfig/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/appconfig/go.mod b/service/appconfig/go.mod index 9b14a51e016..45fdf373914 100644 --- a/service/appconfig/go.mod +++ b/service/appconfig/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appconfig/internal/endpoints/endpoints.go b/service/appconfig/internal/endpoints/endpoints.go index 7610b669504..6cfbd21bb1b 100644 --- a/service/appconfig/internal/endpoints/endpoints.go +++ b/service/appconfig/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AppConfig endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "appconfig.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appconfig.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appconfig-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appconfig-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appconfig.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "appconfig.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appconfig.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appconfig-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appconfig-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appconfig.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "appconfig.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appconfig.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "appconfig.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appconfig.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "appconfig.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appconfig.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appconfig-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appconfig-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appconfig.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/appflow/api_client.go b/service/appflow/api_client.go index 280d749b8e8..2fe0f0df9b2 100644 --- a/service/appflow/api_client.go +++ b/service/appflow/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/appflow/endpoints.go b/service/appflow/endpoints.go index 45ea7fc2235..5d4962ba382 100644 --- a/service/appflow/endpoints.go +++ b/service/appflow/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appflow/generated.json b/service/appflow/generated.json index 055cd0c1c13..c5e37377356 100644 --- a/service/appflow/generated.json +++ b/service/appflow/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/appflow/go.mod b/service/appflow/go.mod index 94338af548a..1e238f3daab 100644 --- a/service/appflow/go.mod +++ b/service/appflow/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appflow/internal/endpoints/endpoints.go b/service/appflow/internal/endpoints/endpoints.go index 80302afd163..8a4fc1108ad 100644 --- a/service/appflow/internal/endpoints/endpoints.go +++ b/service/appflow/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Appflow endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,68 +102,183 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "appflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "appflow.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appflow.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appflow-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appflow-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appflow.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "appflow.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appflow.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "appflow.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appflow.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "appflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/appintegrations/api_client.go b/service/appintegrations/api_client.go index 58f9d4df4c9..e502cd4fb26 100644 --- a/service/appintegrations/api_client.go +++ b/service/appintegrations/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/appintegrations/endpoints.go b/service/appintegrations/endpoints.go index 426bb29e601..f5231663dc8 100644 --- a/service/appintegrations/endpoints.go +++ b/service/appintegrations/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appintegrations/generated.json b/service/appintegrations/generated.json index cf6f74f3fdf..ae4014a71b3 100644 --- a/service/appintegrations/generated.json +++ b/service/appintegrations/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/appintegrations/go.mod b/service/appintegrations/go.mod index 77bbaa3e2d6..f5af54c77cb 100644 --- a/service/appintegrations/go.mod +++ b/service/appintegrations/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appintegrations/internal/endpoints/endpoints.go b/service/appintegrations/internal/endpoints/endpoints.go index 2ad7b1259b5..aa219d27504 100644 --- a/service/appintegrations/internal/endpoints/endpoints.go +++ b/service/appintegrations/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AppIntegrations endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,60 +102,159 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "app-integrations.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "app-integrations.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "app-integrations-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "app-integrations-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "app-integrations.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "app-integrations.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "app-integrations.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "app-integrations-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "app-integrations-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "app-integrations.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "app-integrations.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "app-integrations.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "app-integrations.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "app-integrations.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "app-integrations.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "app-integrations.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "app-integrations-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "app-integrations-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "app-integrations.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/applicationautoscaling/api_client.go b/service/applicationautoscaling/api_client.go index b59cefddb56..a8d84011736 100644 --- a/service/applicationautoscaling/api_client.go +++ b/service/applicationautoscaling/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/applicationautoscaling/endpoints.go b/service/applicationautoscaling/endpoints.go index 089dfa0c95b..fc1c677b068 100644 --- a/service/applicationautoscaling/endpoints.go +++ b/service/applicationautoscaling/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/applicationautoscaling/generated.json b/service/applicationautoscaling/generated.json index 19b471cac16..926846e3fb7 100644 --- a/service/applicationautoscaling/generated.json +++ b/service/applicationautoscaling/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/applicationautoscaling/go.mod b/service/applicationautoscaling/go.mod index c53c74edb98..3fb2d51e339 100644 --- a/service/applicationautoscaling/go.mod +++ b/service/applicationautoscaling/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/applicationautoscaling/internal/endpoints/endpoints.go b/service/applicationautoscaling/internal/endpoints/endpoints.go index f85c82b9999..08a9856111d 100644 --- a/service/applicationautoscaling/internal/endpoints/endpoints.go +++ b/service/applicationautoscaling/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Application Auto Scaling endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,92 +102,231 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "application-autoscaling.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-autoscaling.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "application-autoscaling.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-autoscaling.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "application-autoscaling.{region}.c2s.ic.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "application-autoscaling.{region}.c2s.ic.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "application-autoscaling.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "application-autoscaling.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "application-autoscaling.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-autoscaling-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-autoscaling.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, }, diff --git a/service/applicationcostprofiler/api_client.go b/service/applicationcostprofiler/api_client.go index 0748a7ef960..6a998f4202b 100644 --- a/service/applicationcostprofiler/api_client.go +++ b/service/applicationcostprofiler/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/applicationcostprofiler/endpoints.go b/service/applicationcostprofiler/endpoints.go index 4fa3ef1b179..ee56f21eb84 100644 --- a/service/applicationcostprofiler/endpoints.go +++ b/service/applicationcostprofiler/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/applicationcostprofiler/generated.json b/service/applicationcostprofiler/generated.json index 5748057b76e..4b0f6f1b8e7 100644 --- a/service/applicationcostprofiler/generated.json +++ b/service/applicationcostprofiler/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/applicationcostprofiler/go.mod b/service/applicationcostprofiler/go.mod index 3d4874d187e..d976981642d 100644 --- a/service/applicationcostprofiler/go.mod +++ b/service/applicationcostprofiler/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/applicationcostprofiler/internal/endpoints/endpoints.go b/service/applicationcostprofiler/internal/endpoints/endpoints.go index 2d07e7d5e15..9ca13ae3843 100644 --- a/service/applicationcostprofiler/internal/endpoints/endpoints.go +++ b/service/applicationcostprofiler/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ApplicationCostProfiler endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "application-cost-profiler.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-cost-profiler.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "application-cost-profiler.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-cost-profiler.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "application-cost-profiler.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "application-cost-profiler.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "application-cost-profiler.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "application-cost-profiler.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "application-cost-profiler.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "application-cost-profiler-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "application-cost-profiler.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/applicationdiscoveryservice/api_client.go b/service/applicationdiscoveryservice/api_client.go index 2c363abc070..5cefb3efd38 100644 --- a/service/applicationdiscoveryservice/api_client.go +++ b/service/applicationdiscoveryservice/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/applicationdiscoveryservice/endpoints.go b/service/applicationdiscoveryservice/endpoints.go index 6d513ca650b..4f22a8c6bb1 100644 --- a/service/applicationdiscoveryservice/endpoints.go +++ b/service/applicationdiscoveryservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/applicationdiscoveryservice/generated.json b/service/applicationdiscoveryservice/generated.json index 3888c983989..5044afcb731 100644 --- a/service/applicationdiscoveryservice/generated.json +++ b/service/applicationdiscoveryservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/applicationdiscoveryservice/go.mod b/service/applicationdiscoveryservice/go.mod index 3f08aad8f3b..3e24607f9e6 100644 --- a/service/applicationdiscoveryservice/go.mod +++ b/service/applicationdiscoveryservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/applicationdiscoveryservice/internal/endpoints/endpoints.go b/service/applicationdiscoveryservice/internal/endpoints/endpoints.go index 6da013b04a6..222e8879856 100644 --- a/service/applicationdiscoveryservice/internal/endpoints/endpoints.go +++ b/service/applicationdiscoveryservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Application Discovery Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "discovery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "discovery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "discovery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "discovery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "discovery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "discovery.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "discovery.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "discovery-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "discovery-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "discovery.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "discovery.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "discovery.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "discovery.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "discovery.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "discovery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "discovery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "discovery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "discovery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "discovery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/applicationinsights/api_client.go b/service/applicationinsights/api_client.go index abc6aad1f48..8cb5ca132c1 100644 --- a/service/applicationinsights/api_client.go +++ b/service/applicationinsights/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/applicationinsights/endpoints.go b/service/applicationinsights/endpoints.go index 261adb88c46..a6567ed6600 100644 --- a/service/applicationinsights/endpoints.go +++ b/service/applicationinsights/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/applicationinsights/generated.json b/service/applicationinsights/generated.json index fd66d09ac48..d2c01fb4f2b 100644 --- a/service/applicationinsights/generated.json +++ b/service/applicationinsights/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/applicationinsights/go.mod b/service/applicationinsights/go.mod index 49a49f1816b..0b45d30c1db 100644 --- a/service/applicationinsights/go.mod +++ b/service/applicationinsights/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/applicationinsights/internal/endpoints/endpoints.go b/service/applicationinsights/internal/endpoints/endpoints.go index e42ce06283c..cd9edfe59e7 100644 --- a/service/applicationinsights/internal/endpoints/endpoints.go +++ b/service/applicationinsights/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Application Insights endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,223 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "applicationinsights.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "applicationinsights-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "applicationinsights.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "applicationinsights.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "applicationinsights-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "applicationinsights.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "applicationinsights.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "applicationinsights.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "applicationinsights.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "applicationinsights.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "applicationinsights.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "applicationinsights-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "applicationinsights-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "applicationinsights.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ + Hostname: "applicationinsights.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "applicationinsights.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + }, }, } diff --git a/service/appmesh/api_client.go b/service/appmesh/api_client.go index 9ac7ae71d7c..8093df75e92 100644 --- a/service/appmesh/api_client.go +++ b/service/appmesh/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/appmesh/endpoints.go b/service/appmesh/endpoints.go index e7161178e8c..34dfb7db798 100644 --- a/service/appmesh/endpoints.go +++ b/service/appmesh/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appmesh/generated.json b/service/appmesh/generated.json index 50e5c8918a1..b1b56817712 100644 --- a/service/appmesh/generated.json +++ b/service/appmesh/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/appmesh/go.mod b/service/appmesh/go.mod index a7695240cec..9b26fbefa0f 100644 --- a/service/appmesh/go.mod +++ b/service/appmesh/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appmesh/internal/endpoints/endpoints.go b/service/appmesh/internal/endpoints/endpoints.go index dea6aca8980..5be7b84be8e 100644 --- a/service/appmesh/internal/endpoints/endpoints.go +++ b/service/appmesh/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver App Mesh endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,76 +102,203 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "appmesh.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appmesh.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appmesh-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appmesh-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appmesh.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "appmesh.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appmesh.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appmesh-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appmesh-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appmesh.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "appmesh.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appmesh.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "appmesh.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appmesh.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "appmesh.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appmesh.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appmesh-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appmesh-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appmesh.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/apprunner/api_client.go b/service/apprunner/api_client.go index 42fef850016..cd963fe662d 100644 --- a/service/apprunner/api_client.go +++ b/service/apprunner/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/apprunner/endpoints.go b/service/apprunner/endpoints.go index 6d1ec024ec3..8e43b95b433 100644 --- a/service/apprunner/endpoints.go +++ b/service/apprunner/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/apprunner/generated.json b/service/apprunner/generated.json index 8444a344c49..010f7b747fb 100644 --- a/service/apprunner/generated.json +++ b/service/apprunner/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/apprunner/go.mod b/service/apprunner/go.mod index 537d085e11b..a00075a3129 100644 --- a/service/apprunner/go.mod +++ b/service/apprunner/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/apprunner/internal/endpoints/endpoints.go b/service/apprunner/internal/endpoints/endpoints.go index 957791f2717..70783d0ae2a 100644 --- a/service/apprunner/internal/endpoints/endpoints.go +++ b/service/apprunner/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AppRunner endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,57 +102,150 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "apprunner.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apprunner.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apprunner-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apprunner-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apprunner.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "apprunner.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apprunner.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apprunner-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apprunner-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apprunner.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "apprunner.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apprunner.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "apprunner.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "apprunner.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "apprunner.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "apprunner.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "apprunner-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "apprunner-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "apprunner.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/appstream/api_client.go b/service/appstream/api_client.go index f4974578f30..6f6b127a25f 100644 --- a/service/appstream/api_client.go +++ b/service/appstream/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/appstream/endpoints.go b/service/appstream/endpoints.go index 49c2d119b24..ca022e21467 100644 --- a/service/appstream/endpoints.go +++ b/service/appstream/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appstream/generated.json b/service/appstream/generated.json index a0a010d57b3..95f90eef27e 100644 --- a/service/appstream/generated.json +++ b/service/appstream/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/appstream/go.mod b/service/appstream/go.mod index 00319cc6cd7..b2d24aa9b69 100644 --- a/service/appstream/go.mod +++ b/service/appstream/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appstream/internal/endpoints/endpoints.go b/service/appstream/internal/endpoints/endpoints.go index 4fc8fd0dd08..3ddbd7bfda4 100644 --- a/service/appstream/internal/endpoints/endpoints.go +++ b/service/appstream/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AppStream endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,85 +102,212 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "appstream2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "appstream", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appstream2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appstream2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appstream2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: 0, + }: { + Hostname: "appstream2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "appstream2-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, }, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "appstream2.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appstream2.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appstream2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appstream2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appstream2.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "appstream2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appstream2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "appstream2.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appstream2.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "appstream2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "appstream", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appstream2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appstream2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appstream2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, + }, + { + Variant: 0, + }: { + Hostname: "appstream2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "appstream", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "appstream2-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/appsync/api_client.go b/service/appsync/api_client.go index 298331ab390..1a39036c1c0 100644 --- a/service/appsync/api_client.go +++ b/service/appsync/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/appsync/endpoints.go b/service/appsync/endpoints.go index 67e2b4c691e..9da7a159099 100644 --- a/service/appsync/endpoints.go +++ b/service/appsync/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/appsync/generated.json b/service/appsync/generated.json index 7e1504bdb71..7ce19b0517d 100644 --- a/service/appsync/generated.json +++ b/service/appsync/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/appsync/go.mod b/service/appsync/go.mod index 1d2b07d35ab..9ebae7761e1 100644 --- a/service/appsync/go.mod +++ b/service/appsync/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/appsync/internal/endpoints/endpoints.go b/service/appsync/internal/endpoints/endpoints.go index d2355ce4491..02d431f34c9 100644 --- a/service/appsync/internal/endpoints/endpoints.go +++ b/service/appsync/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AppSync endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,76 +102,203 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "appsync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appsync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appsync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appsync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appsync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "appsync.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appsync.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appsync-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appsync-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appsync.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "appsync.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appsync.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "appsync.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "appsync.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "appsync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "appsync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "appsync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "appsync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "appsync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/athena/api_client.go b/service/athena/api_client.go index 4cc41443277..1481c873dd2 100644 --- a/service/athena/api_client.go +++ b/service/athena/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/athena/endpoints.go b/service/athena/endpoints.go index 2e52b449c4b..fff28755493 100644 --- a/service/athena/endpoints.go +++ b/service/athena/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/athena/generated.json b/service/athena/generated.json index d2ac1848565..5114c458017 100644 --- a/service/athena/generated.json +++ b/service/athena/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/athena/go.mod b/service/athena/go.mod index f651abc6c17..1fe0d1a6a02 100644 --- a/service/athena/go.mod +++ b/service/athena/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/athena/internal/endpoints/endpoints.go b/service/athena/internal/endpoints/endpoints.go index b81e3557585..5fbf754b74f 100644 --- a/service/athena/internal/endpoints/endpoints.go +++ b/service/athena/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Athena endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "athena.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "athena.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "athena-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "athena.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "athena.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "athena.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "athena-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "athena.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "athena.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "athena.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "athena.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "athena.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "athena.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "athena.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "athena-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "athena.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "athena-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "athena-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/auditmanager/api_client.go b/service/auditmanager/api_client.go index 88b24bea165..6250e55b06b 100644 --- a/service/auditmanager/api_client.go +++ b/service/auditmanager/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/auditmanager/endpoints.go b/service/auditmanager/endpoints.go index 3b5616c33be..1a38bc7bd0b 100644 --- a/service/auditmanager/endpoints.go +++ b/service/auditmanager/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/auditmanager/generated.json b/service/auditmanager/generated.json index 508c8f6ff16..6f6246f184f 100644 --- a/service/auditmanager/generated.json +++ b/service/auditmanager/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/auditmanager/go.mod b/service/auditmanager/go.mod index 5bd71e68d7e..2bf1f4a574a 100644 --- a/service/auditmanager/go.mod +++ b/service/auditmanager/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/auditmanager/internal/endpoints/endpoints.go b/service/auditmanager/internal/endpoints/endpoints.go index a4ca34775b2..9308b0d4bc1 100644 --- a/service/auditmanager/internal/endpoints/endpoints.go +++ b/service/auditmanager/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver AuditManager endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,64 +102,171 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "auditmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "auditmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "auditmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "auditmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "auditmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "auditmanager.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "auditmanager.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "auditmanager-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "auditmanager-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "auditmanager.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "auditmanager.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "auditmanager.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "auditmanager.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "auditmanager.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "auditmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "auditmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "auditmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "auditmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "auditmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/autoscaling/api_client.go b/service/autoscaling/api_client.go index 7dbb4c9d053..8300319ae6f 100644 --- a/service/autoscaling/api_client.go +++ b/service/autoscaling/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/autoscaling/endpoints.go b/service/autoscaling/endpoints.go index ac12f425451..d977cf2875c 100644 --- a/service/autoscaling/endpoints.go +++ b/service/autoscaling/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/autoscaling/generated.json b/service/autoscaling/generated.json index 99e692d4e87..b7d99e38ed0 100644 --- a/service/autoscaling/generated.json +++ b/service/autoscaling/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/autoscaling/go.mod b/service/autoscaling/go.mod index 316ac1b1e21..990867946b9 100644 --- a/service/autoscaling/go.mod +++ b/service/autoscaling/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/autoscaling/internal/endpoints/endpoints.go b/service/autoscaling/internal/endpoints/endpoints.go index 1e38c7b73c3..ec433efa5b7 100644 --- a/service/autoscaling/internal/endpoints/endpoints.go +++ b/service/autoscaling/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Auto Scaling endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,94 +102,233 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "autoscaling.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "autoscaling.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, }, diff --git a/service/autoscalingplans/api_client.go b/service/autoscalingplans/api_client.go index e468d8db02c..ffabf929105 100644 --- a/service/autoscalingplans/api_client.go +++ b/service/autoscalingplans/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/autoscalingplans/endpoints.go b/service/autoscalingplans/endpoints.go index a8d6c5ea018..74e2f0eab53 100644 --- a/service/autoscalingplans/endpoints.go +++ b/service/autoscalingplans/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/autoscalingplans/generated.json b/service/autoscalingplans/generated.json index f1cde7f23ef..e4f113b9e0e 100644 --- a/service/autoscalingplans/generated.json +++ b/service/autoscalingplans/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/autoscalingplans/go.mod b/service/autoscalingplans/go.mod index 93073a966bb..92447517b00 100644 --- a/service/autoscalingplans/go.mod +++ b/service/autoscalingplans/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/autoscalingplans/internal/endpoints/endpoints.go b/service/autoscalingplans/internal/endpoints/endpoints.go index 14dfc2b7cb9..b84092ee3a5 100644 --- a/service/autoscalingplans/internal/endpoints/endpoints.go +++ b/service/autoscalingplans/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Auto Scaling Plans endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,85 +102,218 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling-plans.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling-plans.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling-plans.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling-plans.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling-plans.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "autoscaling-plans.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling-plans.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "autoscaling-plans.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "autoscaling-plans.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "autoscaling-plans-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "autoscaling-plans.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, }, diff --git a/service/backup/api_client.go b/service/backup/api_client.go index d1e38c065bb..369c8f35e1a 100644 --- a/service/backup/api_client.go +++ b/service/backup/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/backup/endpoints.go b/service/backup/endpoints.go index fa901f2cb08..9e0cc6e3b84 100644 --- a/service/backup/endpoints.go +++ b/service/backup/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/backup/generated.json b/service/backup/generated.json index 894448a5c65..1df0321c42c 100644 --- a/service/backup/generated.json +++ b/service/backup/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/backup/go.mod b/service/backup/go.mod index a2090fa2e2d..51a315aeb25 100644 --- a/service/backup/go.mod +++ b/service/backup/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/backup/internal/endpoints/endpoints.go b/service/backup/internal/endpoints/endpoints.go index 088393e1b3a..7e3764ca51c 100644 --- a/service/backup/internal/endpoints/endpoints.go +++ b/service/backup/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Backup endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,83 +102,216 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "backup.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "backup.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "backup-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "backup-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "backup.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "backup.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "backup.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "backup-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "backup-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "backup.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "backup.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "backup.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "backup.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "backup.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "backup.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "backup.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "backup-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "backup-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "backup.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/batch/api_client.go b/service/batch/api_client.go index 142d2207447..efc583a2034 100644 --- a/service/batch/api_client.go +++ b/service/batch/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/batch/endpoints.go b/service/batch/endpoints.go index 93d2f7c2ae5..f72f8735d03 100644 --- a/service/batch/endpoints.go +++ b/service/batch/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/batch/generated.json b/service/batch/generated.json index f006b094c3f..fe09a9286a9 100644 --- a/service/batch/generated.json +++ b/service/batch/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/batch/go.mod b/service/batch/go.mod index 41df4404bb6..2a0471221da 100644 --- a/service/batch/go.mod +++ b/service/batch/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/batch/internal/endpoints/endpoints.go b/service/batch/internal/endpoints/endpoints.go index ea968c7bda3..c651726afab 100644 --- a/service/batch/internal/endpoints/endpoints.go +++ b/service/batch/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Batch endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "batch.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "batch.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "batch-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "batch-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "batch.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "fips.batch.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "fips.batch.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "fips.batch.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "fips.batch.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.batch.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.batch.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.batch.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.batch.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "batch.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "batch.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "batch-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "batch-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "batch.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "batch.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "batch.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "batch.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "batch.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "batch.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "batch.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "batch-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "batch-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "batch.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "batch.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "batch.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "batch.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "batch.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/braket/api_client.go b/service/braket/api_client.go index 4b19d51d569..30eca52bb9a 100644 --- a/service/braket/api_client.go +++ b/service/braket/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/braket/endpoints.go b/service/braket/endpoints.go index da6650932eb..97192a9dd76 100644 --- a/service/braket/endpoints.go +++ b/service/braket/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/braket/generated.json b/service/braket/generated.json index 1a04d91c4cd..e25f47531aa 100644 --- a/service/braket/generated.json +++ b/service/braket/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/braket/go.mod b/service/braket/go.mod index 89cad8199db..dfc3610f58f 100644 --- a/service/braket/go.mod +++ b/service/braket/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/braket/internal/endpoints/endpoints.go b/service/braket/internal/endpoints/endpoints.go index 59e35fe9988..826f1e9d719 100644 --- a/service/braket/internal/endpoints/endpoints.go +++ b/service/braket/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Braket endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,55 +102,144 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "braket.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "braket.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "braket-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "braket-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "braket.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "braket.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "braket.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "braket-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "braket-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "braket.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "braket.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "braket.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "braket.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "braket.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "braket.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "braket.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "braket-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "braket-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "braket.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/budgets/api_client.go b/service/budgets/api_client.go index c186213f5f3..6e39b81ada1 100644 --- a/service/budgets/api_client.go +++ b/service/budgets/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/budgets/endpoints.go b/service/budgets/endpoints.go index 42e345ebdee..c93f0a89a37 100644 --- a/service/budgets/endpoints.go +++ b/service/budgets/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/budgets/generated.json b/service/budgets/generated.json index 947494004ea..b0dd7db4eca 100644 --- a/service/budgets/generated.json +++ b/service/budgets/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/budgets/go.mod b/service/budgets/go.mod index dff594d7c66..fb53d1a5e52 100644 --- a/service/budgets/go.mod +++ b/service/budgets/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/budgets/internal/endpoints/endpoints.go b/service/budgets/internal/endpoints/endpoints.go index b703951419d..f009f8785fc 100644 --- a/service/budgets/internal/endpoints/endpoints.go +++ b/service/budgets/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Budgets endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "budgets.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "budgets.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "budgets-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "budgets-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "budgets.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "budgets.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -74,16 +148,43 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "budgets.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "budgets.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "budgets-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "budgets-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "budgets.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "budgets.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -93,30 +194,63 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "budgets.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "budgets.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "budgets.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "budgets.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "budgets.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "budgets.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "budgets-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "budgets-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "budgets.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/chime/api_client.go b/service/chime/api_client.go index 4276bda4282..2c5099d2bf1 100644 --- a/service/chime/api_client.go +++ b/service/chime/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/chime/endpoints.go b/service/chime/endpoints.go index a60d6307cb1..a0ab2ab3df3 100644 --- a/service/chime/endpoints.go +++ b/service/chime/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/chime/generated.json b/service/chime/generated.json index 1e9eed180ed..704f9c13631 100644 --- a/service/chime/generated.json +++ b/service/chime/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/chime/go.mod b/service/chime/go.mod index d17f0fd7207..6017aa60373 100644 --- a/service/chime/go.mod +++ b/service/chime/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/chime/internal/endpoints/endpoints.go b/service/chime/internal/endpoints/endpoints.go index 354c011c1f3..78c039975ba 100644 --- a/service/chime/internal/endpoints/endpoints.go +++ b/service/chime/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Chime endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "chime.us-east-1.amazonaws.com", Protocols: []string{"https"}, CredentialScope: endpoints.CredentialScope{ @@ -75,40 +149,98 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "chime.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "chime.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "chime-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "chime-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "chime.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "chime.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "chime.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "chime.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "chime.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/chimesdkidentity/api_client.go b/service/chimesdkidentity/api_client.go index a58c922df09..0b6047e026a 100644 --- a/service/chimesdkidentity/api_client.go +++ b/service/chimesdkidentity/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/chimesdkidentity/endpoints.go b/service/chimesdkidentity/endpoints.go index 6047dc520f4..ee0cd6e497b 100644 --- a/service/chimesdkidentity/endpoints.go +++ b/service/chimesdkidentity/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/chimesdkidentity/generated.json b/service/chimesdkidentity/generated.json index c5335415da1..c9cb4026d12 100644 --- a/service/chimesdkidentity/generated.json +++ b/service/chimesdkidentity/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/chimesdkidentity/go.mod b/service/chimesdkidentity/go.mod index 31b6e787469..b1febb195d2 100644 --- a/service/chimesdkidentity/go.mod +++ b/service/chimesdkidentity/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/chimesdkidentity/internal/endpoints/endpoints.go b/service/chimesdkidentity/internal/endpoints/endpoints.go index a9a16aa0f45..3dbde87523e 100644 --- a/service/chimesdkidentity/internal/endpoints/endpoints.go +++ b/service/chimesdkidentity/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Chime SDK Identity endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "identity-chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identity-chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identity-chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identity-chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identity-chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identity-chime-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "identity-chime-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "identity-chime.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identity-chime.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identity-chime-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identity-chime-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identity-chime.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "identity-chime.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "identity-chime.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "identity-chime.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "identity-chime.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "identity-chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identity-chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identity-chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identity-chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identity-chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/chimesdkmessaging/api_client.go b/service/chimesdkmessaging/api_client.go index badd0e180a0..eaf7c7cf6e6 100644 --- a/service/chimesdkmessaging/api_client.go +++ b/service/chimesdkmessaging/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/chimesdkmessaging/endpoints.go b/service/chimesdkmessaging/endpoints.go index dc3a21c3a2e..fef6be41afd 100644 --- a/service/chimesdkmessaging/endpoints.go +++ b/service/chimesdkmessaging/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/chimesdkmessaging/generated.json b/service/chimesdkmessaging/generated.json index 9c42a9c0563..ab65a370862 100644 --- a/service/chimesdkmessaging/generated.json +++ b/service/chimesdkmessaging/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/chimesdkmessaging/go.mod b/service/chimesdkmessaging/go.mod index 111153c5546..317789aacd0 100644 --- a/service/chimesdkmessaging/go.mod +++ b/service/chimesdkmessaging/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/chimesdkmessaging/internal/endpoints/endpoints.go b/service/chimesdkmessaging/internal/endpoints/endpoints.go index 9ebee50d837..e311399a159 100644 --- a/service/chimesdkmessaging/internal/endpoints/endpoints.go +++ b/service/chimesdkmessaging/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Chime SDK Messaging endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "messaging-chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "messaging-chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "messaging-chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "messaging-chime-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "messaging-chime-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "messaging-chime.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "messaging-chime-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "messaging-chime.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "messaging-chime.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "messaging-chime.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "messaging-chime.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "messaging-chime.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "messaging-chime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "messaging-chime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "messaging-chime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "messaging-chime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cloud9/api_client.go b/service/cloud9/api_client.go index 779e3046ce3..6153c1fb8a4 100644 --- a/service/cloud9/api_client.go +++ b/service/cloud9/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloud9/endpoints.go b/service/cloud9/endpoints.go index e169fdabf54..7bf62ec7456 100644 --- a/service/cloud9/endpoints.go +++ b/service/cloud9/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloud9/generated.json b/service/cloud9/generated.json index eb5bc43d685..7e33a8c459e 100644 --- a/service/cloud9/generated.json +++ b/service/cloud9/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloud9/go.mod b/service/cloud9/go.mod index d6c26f43f78..29041725beb 100644 --- a/service/cloud9/go.mod +++ b/service/cloud9/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloud9/internal/endpoints/endpoints.go b/service/cloud9/internal/endpoints/endpoints.go index 2cd44a6c591..aecc7175d2c 100644 --- a/service/cloud9/internal/endpoints/endpoints.go +++ b/service/cloud9/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cloud9 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,73 +102,198 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloud9.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloud9.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloud9-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloud9-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloud9.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloud9.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloud9.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloud9-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloud9-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloud9.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloud9.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloud9.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloud9.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloud9.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloud9.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloud9.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloud9-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloud9-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloud9.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cloudcontrol/api_client.go b/service/cloudcontrol/api_client.go index 049a9977083..70185b89fa0 100644 --- a/service/cloudcontrol/api_client.go +++ b/service/cloudcontrol/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/cloudcontrol/endpoints.go b/service/cloudcontrol/endpoints.go index 7307df7cbf2..b43baea72fb 100644 --- a/service/cloudcontrol/endpoints.go +++ b/service/cloudcontrol/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudcontrol/generated.json b/service/cloudcontrol/generated.json index d127ae96faf..ec25d47ad4d 100644 --- a/service/cloudcontrol/generated.json +++ b/service/cloudcontrol/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/cloudcontrol/go.mod b/service/cloudcontrol/go.mod index 550bca9c107..d7b5a1273bf 100644 --- a/service/cloudcontrol/go.mod +++ b/service/cloudcontrol/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudcontrol/internal/endpoints/endpoints.go b/service/cloudcontrol/internal/endpoints/endpoints.go index 545c9a6bf6f..2b44cc4f6f5 100644 --- a/service/cloudcontrol/internal/endpoints/endpoints.go +++ b/service/cloudcontrol/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudControl endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,313 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudcontrolapi.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudcontrolapi.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudcontrolapi.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudcontrolapi.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudcontrolapi.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudcontrolapi.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudcontrolapi.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudcontrolapi.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudcontrolapi.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudcontrolapi-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudcontrolapi.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "cloudcontrolapi-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudcontrolapi-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/clouddirectory/api_client.go b/service/clouddirectory/api_client.go index e5748fdb52a..58481dc0a7d 100644 --- a/service/clouddirectory/api_client.go +++ b/service/clouddirectory/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/clouddirectory/endpoints.go b/service/clouddirectory/endpoints.go index 6ae3e451054..3ae7bedb1da 100644 --- a/service/clouddirectory/endpoints.go +++ b/service/clouddirectory/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/clouddirectory/generated.json b/service/clouddirectory/generated.json index 90513542c45..cf503178bdb 100644 --- a/service/clouddirectory/generated.json +++ b/service/clouddirectory/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/clouddirectory/go.mod b/service/clouddirectory/go.mod index be76961ae94..8d76088ea86 100644 --- a/service/clouddirectory/go.mod +++ b/service/clouddirectory/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/clouddirectory/internal/endpoints/endpoints.go b/service/clouddirectory/internal/endpoints/endpoints.go index 4baf5b24ad9..dd70ca8496d 100644 --- a/service/clouddirectory/internal/endpoints/endpoints.go +++ b/service/clouddirectory/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudDirectory endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,66 +102,169 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "clouddirectory.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "clouddirectory-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "clouddirectory.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "clouddirectory.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "clouddirectory-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "clouddirectory.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "clouddirectory.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "clouddirectory.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "clouddirectory.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "clouddirectory.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "clouddirectory.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "clouddirectory-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "clouddirectory-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "clouddirectory.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/cloudformation/api_client.go b/service/cloudformation/api_client.go index 023684b1f94..f49372b901d 100644 --- a/service/cloudformation/api_client.go +++ b/service/cloudformation/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/cloudformation/endpoints.go b/service/cloudformation/endpoints.go index b56969f7dac..36b8f7d0762 100644 --- a/service/cloudformation/endpoints.go +++ b/service/cloudformation/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudformation/generated.json b/service/cloudformation/generated.json index 5f6f1e8b3c1..13c87c8841a 100644 --- a/service/cloudformation/generated.json +++ b/service/cloudformation/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/cloudformation/go.mod b/service/cloudformation/go.mod index df6fdb5743f..582bc3bc2b1 100644 --- a/service/cloudformation/go.mod +++ b/service/cloudformation/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudformation/internal/endpoints/endpoints.go b/service/cloudformation/internal/endpoints/endpoints.go index 7640e678545..1f8ebac5f18 100644 --- a/service/cloudformation/internal/endpoints/endpoints.go +++ b/service/cloudformation/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudFormation endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudformation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudformation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudformation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudformation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "cloudformation-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "cloudformation-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "cloudformation-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "cloudformation-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudformation.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudformation.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudformation-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudformation.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudformation.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudformation.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudformation.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudformation.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudformation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudformation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudformation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudformation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudformation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "cloudformation.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "cloudformation.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/cloudfront/api_client.go b/service/cloudfront/api_client.go index dc438a9415d..86dfa4284f9 100644 --- a/service/cloudfront/api_client.go +++ b/service/cloudfront/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudfront/endpoints.go b/service/cloudfront/endpoints.go index c74950aec05..86c818cc3b9 100644 --- a/service/cloudfront/endpoints.go +++ b/service/cloudfront/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudfront/generated.json b/service/cloudfront/generated.json index d08255996ac..3aa251fcccf 100644 --- a/service/cloudfront/generated.json +++ b/service/cloudfront/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/cloudfront/go.mod b/service/cloudfront/go.mod index c0a3972d047..0ceda8dc461 100644 --- a/service/cloudfront/go.mod +++ b/service/cloudfront/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudfront/internal/endpoints/endpoints.go b/service/cloudfront/internal/endpoints/endpoints.go index 0a6cf0f0e8d..520014a5ab4 100644 --- a/service/cloudfront/internal/endpoints/endpoints.go +++ b/service/cloudfront/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudFront endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudfront.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudfront.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudfront-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudfront-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudfront.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "cloudfront.amazonaws.com", Protocols: []string{"http", "https"}, CredentialScope: endpoints.CredentialScope{ @@ -75,16 +149,43 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudfront.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudfront.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudfront-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudfront-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudfront.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "cloudfront.cn-northwest-1.amazonaws.com.cn", Protocols: []string{"http", "https"}, CredentialScope: endpoints.CredentialScope{ @@ -95,30 +196,63 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudfront.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudfront.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudfront.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudfront.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudfront.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudfront.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudfront-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudfront-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudfront.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cloudhsm/api_client.go b/service/cloudhsm/api_client.go index db6eaa831b5..fea9ebe5f6c 100644 --- a/service/cloudhsm/api_client.go +++ b/service/cloudhsm/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudhsm/endpoints.go b/service/cloudhsm/endpoints.go index 255efb6f81a..dcd927c6ee2 100644 --- a/service/cloudhsm/endpoints.go +++ b/service/cloudhsm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudhsm/generated.json b/service/cloudhsm/generated.json index 54d8891a900..c37687959e5 100644 --- a/service/cloudhsm/generated.json +++ b/service/cloudhsm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudhsm/go.mod b/service/cloudhsm/go.mod index e2330ecfd31..4bf449c99ae 100644 --- a/service/cloudhsm/go.mod +++ b/service/cloudhsm/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudhsm/internal/endpoints/endpoints.go b/service/cloudhsm/internal/endpoints/endpoints.go index 56b90bf2cab..53aca03c315 100644 --- a/service/cloudhsm/internal/endpoints/endpoints.go +++ b/service/cloudhsm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudHSM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,172 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudhsm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudhsm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/cloudhsmv2/api_client.go b/service/cloudhsmv2/api_client.go index 5021e5bb401..1229684c5f3 100644 --- a/service/cloudhsmv2/api_client.go +++ b/service/cloudhsmv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudhsmv2/endpoints.go b/service/cloudhsmv2/endpoints.go index bef2f0299db..da659a227b2 100644 --- a/service/cloudhsmv2/endpoints.go +++ b/service/cloudhsmv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudhsmv2/generated.json b/service/cloudhsmv2/generated.json index eba18fa4c76..3cdc15a7903 100644 --- a/service/cloudhsmv2/generated.json +++ b/service/cloudhsmv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudhsmv2/go.mod b/service/cloudhsmv2/go.mod index b91490af9f5..488b93ef7de 100644 --- a/service/cloudhsmv2/go.mod +++ b/service/cloudhsmv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudhsmv2/internal/endpoints/endpoints.go b/service/cloudhsmv2/internal/endpoints/endpoints.go index 9b6bcb20238..ec42132ae07 100644 --- a/service/cloudhsmv2/internal/endpoints/endpoints.go +++ b/service/cloudhsmv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudHSM V2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,85 +102,232 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsmv2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "cloudhsm", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsmv2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsmv2.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsmv2.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsmv2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudhsmv2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsmv2.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudhsmv2.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudhsmv2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "cloudhsm", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudhsmv2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, + }, + { + Variant: 0, + }: { + Hostname: "cloudhsmv2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "cloudhsm", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/cloudsearch/api_client.go b/service/cloudsearch/api_client.go index 2bce88ee85d..3000d4f4a14 100644 --- a/service/cloudsearch/api_client.go +++ b/service/cloudsearch/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudsearch/endpoints.go b/service/cloudsearch/endpoints.go index 8c213099b7b..0ece5a8ed2c 100644 --- a/service/cloudsearch/endpoints.go +++ b/service/cloudsearch/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudsearch/generated.json b/service/cloudsearch/generated.json index 244ab1ded26..b171a73c41e 100644 --- a/service/cloudsearch/generated.json +++ b/service/cloudsearch/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudsearch/go.mod b/service/cloudsearch/go.mod index a21b27baa00..a60d2ed7bf0 100644 --- a/service/cloudsearch/go.mod +++ b/service/cloudsearch/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudsearch/internal/endpoints/endpoints.go b/service/cloudsearch/internal/endpoints/endpoints.go index db302055ec8..a693f9495d6 100644 --- a/service/cloudsearch/internal/endpoints/endpoints.go +++ b/service/cloudsearch/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudSearch endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,62 +102,165 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearch.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearch-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearch.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearch.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearch-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearch.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearch.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudsearch.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearch.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudsearch.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearch.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearch-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearch-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearch.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cloudsearchdomain/api_client.go b/service/cloudsearchdomain/api_client.go index e462c68602e..d86ee649ef4 100644 --- a/service/cloudsearchdomain/api_client.go +++ b/service/cloudsearchdomain/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudsearchdomain/endpoints.go b/service/cloudsearchdomain/endpoints.go index 7244ae1b0d4..ad36f039df3 100644 --- a/service/cloudsearchdomain/endpoints.go +++ b/service/cloudsearchdomain/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudsearchdomain/generated.json b/service/cloudsearchdomain/generated.json index 6fce1eae492..18e727d4489 100644 --- a/service/cloudsearchdomain/generated.json +++ b/service/cloudsearchdomain/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudsearchdomain/go.mod b/service/cloudsearchdomain/go.mod index 3264c78c667..fd8c6488030 100644 --- a/service/cloudsearchdomain/go.mod +++ b/service/cloudsearchdomain/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudsearchdomain/internal/endpoints/endpoints.go b/service/cloudsearchdomain/internal/endpoints/endpoints.go index 9c9c4ac6eb0..736df405aa6 100644 --- a/service/cloudsearchdomain/internal/endpoints/endpoints.go +++ b/service/cloudsearchdomain/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudSearch Domain endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearchdomain.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearchdomain.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearchdomain.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearchdomain.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearchdomain.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudsearchdomain.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearchdomain.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudsearchdomain.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudsearchdomain.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudsearchdomain-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudsearchdomain.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cloudtrail/api_client.go b/service/cloudtrail/api_client.go index e7a975dcd14..1f442784463 100644 --- a/service/cloudtrail/api_client.go +++ b/service/cloudtrail/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudtrail/endpoints.go b/service/cloudtrail/endpoints.go index d30dbe20c4d..6dd47fa96b4 100644 --- a/service/cloudtrail/endpoints.go +++ b/service/cloudtrail/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudtrail/generated.json b/service/cloudtrail/generated.json index c7bbe93e42d..1680516b150 100644 --- a/service/cloudtrail/generated.json +++ b/service/cloudtrail/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudtrail/go.mod b/service/cloudtrail/go.mod index 121c520345c..1dbb9931ecf 100644 --- a/service/cloudtrail/go.mod +++ b/service/cloudtrail/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudtrail/internal/endpoints/endpoints.go b/service/cloudtrail/internal/endpoints/endpoints.go index 73ba89adf03..9f9fba07fcc 100644 --- a/service/cloudtrail/internal/endpoints/endpoints.go +++ b/service/cloudtrail/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudTrail endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,291 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cloudtrail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudtrail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "cloudtrail-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "cloudtrail-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "cloudtrail-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "cloudtrail-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cloudtrail.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudtrail.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cloudtrail.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudtrail.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cloudtrail.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cloudtrail.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cloudtrail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cloudtrail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cloudtrail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cloudtrail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "cloudtrail.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "cloudtrail.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/cloudwatch/api_client.go b/service/cloudwatch/api_client.go index 20b2aa5402e..f72eb6887af 100644 --- a/service/cloudwatch/api_client.go +++ b/service/cloudwatch/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudwatch/endpoints.go b/service/cloudwatch/endpoints.go index ca67010d140..35365325df6 100644 --- a/service/cloudwatch/endpoints.go +++ b/service/cloudwatch/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudwatch/generated.json b/service/cloudwatch/generated.json index 840046217b6..9b18f7f882e 100644 --- a/service/cloudwatch/generated.json +++ b/service/cloudwatch/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/cloudwatch/go.mod b/service/cloudwatch/go.mod index 5455bb5382b..ba9d6013846 100644 --- a/service/cloudwatch/go.mod +++ b/service/cloudwatch/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudwatch/internal/endpoints/endpoints.go b/service/cloudwatch/internal/endpoints/endpoints.go index 6d29f19ecac..c69ef365b5c 100644 --- a/service/cloudwatch/internal/endpoints/endpoints.go +++ b/service/cloudwatch/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudWatch endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "monitoring.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "monitoring.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "monitoring-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "monitoring.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "monitoring-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "monitoring-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "monitoring-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "monitoring-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "monitoring.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "monitoring.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "monitoring-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "monitoring.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "monitoring.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "monitoring.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "monitoring.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "monitoring.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "monitoring.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "monitoring.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "monitoring-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "monitoring.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "monitoring.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "monitoring.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "monitoring.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/cloudwatchevents/api_client.go b/service/cloudwatchevents/api_client.go index 2a62436da0e..367face1255 100644 --- a/service/cloudwatchevents/api_client.go +++ b/service/cloudwatchevents/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudwatchevents/endpoints.go b/service/cloudwatchevents/endpoints.go index 25a0cfd89a2..fc61bf34c69 100644 --- a/service/cloudwatchevents/endpoints.go +++ b/service/cloudwatchevents/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudwatchevents/generated.json b/service/cloudwatchevents/generated.json index 60acae12cb8..c438f5c2cd1 100644 --- a/service/cloudwatchevents/generated.json +++ b/service/cloudwatchevents/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudwatchevents/go.mod b/service/cloudwatchevents/go.mod index 4f53b1da6af..1cc819abcf4 100644 --- a/service/cloudwatchevents/go.mod +++ b/service/cloudwatchevents/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudwatchevents/internal/endpoints/endpoints.go b/service/cloudwatchevents/internal/endpoints/endpoints.go index 0e74c6fd8f9..d3c973fa0c1 100644 --- a/service/cloudwatchevents/internal/endpoints/endpoints.go +++ b/service/cloudwatchevents/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudWatch Events endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "events-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "events-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "events-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "events-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "events.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "events.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "events.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "events.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/cloudwatchlogs/api_client.go b/service/cloudwatchlogs/api_client.go index dff256c1526..1ca981ff234 100644 --- a/service/cloudwatchlogs/api_client.go +++ b/service/cloudwatchlogs/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cloudwatchlogs/endpoints.go b/service/cloudwatchlogs/endpoints.go index c78239bf20b..263b5299cc3 100644 --- a/service/cloudwatchlogs/endpoints.go +++ b/service/cloudwatchlogs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cloudwatchlogs/generated.json b/service/cloudwatchlogs/generated.json index 287ac2d99a5..ef377a4160c 100644 --- a/service/cloudwatchlogs/generated.json +++ b/service/cloudwatchlogs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cloudwatchlogs/go.mod b/service/cloudwatchlogs/go.mod index b89df78aecf..fa25d3cab9b 100644 --- a/service/cloudwatchlogs/go.mod +++ b/service/cloudwatchlogs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cloudwatchlogs/internal/endpoints/endpoints.go b/service/cloudwatchlogs/internal/endpoints/endpoints.go index 2cf38d0d427..23328000547 100644 --- a/service/cloudwatchlogs/internal/endpoints/endpoints.go +++ b/service/cloudwatchlogs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CloudWatch Logs endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "logs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "logs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "logs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "logs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "logs-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "logs-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "logs-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "logs-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "logs.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "logs.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "logs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "logs.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "logs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "logs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "logs.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "logs.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "logs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "logs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "logs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "logs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "logs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "logs.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "logs.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/codeartifact/api_client.go b/service/codeartifact/api_client.go index e1df7843750..917c4c140ce 100644 --- a/service/codeartifact/api_client.go +++ b/service/codeartifact/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codeartifact/endpoints.go b/service/codeartifact/endpoints.go index d58a8b89ff0..38a3d2e50a1 100644 --- a/service/codeartifact/endpoints.go +++ b/service/codeartifact/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codeartifact/generated.json b/service/codeartifact/generated.json index 2d82f271963..31e96647082 100644 --- a/service/codeartifact/generated.json +++ b/service/codeartifact/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codeartifact/go.mod b/service/codeartifact/go.mod index 97895e1fa92..4005606a123 100644 --- a/service/codeartifact/go.mod +++ b/service/codeartifact/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codeartifact/internal/endpoints/endpoints.go b/service/codeartifact/internal/endpoints/endpoints.go index f5dd3c3da7c..7df911e6fef 100644 --- a/service/codeartifact/internal/endpoints/endpoints.go +++ b/service/codeartifact/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver codeartifact endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,65 +102,174 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codeartifact.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeartifact.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeartifact-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeartifact-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeartifact.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codeartifact.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeartifact.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeartifact-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeartifact-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeartifact.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codeartifact.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeartifact.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codeartifact.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeartifact.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codeartifact.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeartifact.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeartifact-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeartifact-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeartifact.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/codebuild/api_client.go b/service/codebuild/api_client.go index b061822073d..5dd3d32f161 100644 --- a/service/codebuild/api_client.go +++ b/service/codebuild/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codebuild/endpoints.go b/service/codebuild/endpoints.go index 1226eabbe8f..b0d66c0ed61 100644 --- a/service/codebuild/endpoints.go +++ b/service/codebuild/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codebuild/generated.json b/service/codebuild/generated.json index 5222eef9cdb..2b6692aa3fd 100644 --- a/service/codebuild/generated.json +++ b/service/codebuild/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codebuild/go.mod b/service/codebuild/go.mod index deb7375c54c..0468b3c3d87 100644 --- a/service/codebuild/go.mod +++ b/service/codebuild/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codebuild/internal/endpoints/endpoints.go b/service/codebuild/internal/endpoints/endpoints.go index 53c4d38f786..a26bbacd92b 100644 --- a/service/codebuild/internal/endpoints/endpoints.go +++ b/service/codebuild/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeBuild endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,305 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codebuild.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codebuild.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codebuild-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codebuild.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codebuild.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codebuild.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codebuild-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codebuild.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codebuild.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codebuild.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codebuild.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codebuild.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codebuild.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codebuild.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codebuild-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codebuild.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codebuild-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "codebuild-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/codecommit/api_client.go b/service/codecommit/api_client.go index d236d06123a..fa76d56d442 100644 --- a/service/codecommit/api_client.go +++ b/service/codecommit/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/codecommit/endpoints.go b/service/codecommit/endpoints.go index 84cf579f930..575cf592190 100644 --- a/service/codecommit/endpoints.go +++ b/service/codecommit/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codecommit/generated.json b/service/codecommit/generated.json index f3e87f0ea5c..3876412ea30 100644 --- a/service/codecommit/generated.json +++ b/service/codecommit/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codecommit/go.mod b/service/codecommit/go.mod index c85e3d6432f..6741c6d4125 100644 --- a/service/codecommit/go.mod +++ b/service/codecommit/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codecommit/internal/endpoints/endpoints.go b/service/codecommit/internal/endpoints/endpoints.go index 9dbee17801a..bfce44e30af 100644 --- a/service/codecommit/internal/endpoints/endpoints.go +++ b/service/codecommit/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeCommit endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,95 +102,232 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codecommit.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codecommit.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codecommit-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codecommit-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codecommit.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "codecommit-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codecommit.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codecommit.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codecommit-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codecommit-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codecommit.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codecommit.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codecommit.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codecommit.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codecommit.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codecommit.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codecommit.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codecommit-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codecommit-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codecommit.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "codecommit-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/codedeploy/api_client.go b/service/codedeploy/api_client.go index 45c020046d4..774fdb9d14e 100644 --- a/service/codedeploy/api_client.go +++ b/service/codedeploy/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codedeploy/endpoints.go b/service/codedeploy/endpoints.go index 467d90fbfd0..0cd8375d204 100644 --- a/service/codedeploy/endpoints.go +++ b/service/codedeploy/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codedeploy/generated.json b/service/codedeploy/generated.json index 7408f67ad46..fdb4f06899a 100644 --- a/service/codedeploy/generated.json +++ b/service/codedeploy/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/codedeploy/go.mod b/service/codedeploy/go.mod index 6d41f17b5c1..44e6bd8a237 100644 --- a/service/codedeploy/go.mod +++ b/service/codedeploy/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codedeploy/internal/endpoints/endpoints.go b/service/codedeploy/internal/endpoints/endpoints.go index 23519182713..8999714acec 100644 --- a/service/codedeploy/internal/endpoints/endpoints.go +++ b/service/codedeploy/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeDeploy endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,125 +102,318 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codedeploy.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codedeploy.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codedeploy-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codedeploy.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codedeploy.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codedeploy.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codedeploy-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codedeploy.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codedeploy.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codedeploy.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codedeploy.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codedeploy.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codedeploy.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codedeploy.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codedeploy-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codedeploy.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codedeploy-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "codedeploy-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/codeguruprofiler/api_client.go b/service/codeguruprofiler/api_client.go index 01b69f1f7e7..cc02468231d 100644 --- a/service/codeguruprofiler/api_client.go +++ b/service/codeguruprofiler/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codeguruprofiler/endpoints.go b/service/codeguruprofiler/endpoints.go index 94902cc440f..12a06f528a2 100644 --- a/service/codeguruprofiler/endpoints.go +++ b/service/codeguruprofiler/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codeguruprofiler/generated.json b/service/codeguruprofiler/generated.json index 5bc52f1cb8d..43696b61e60 100644 --- a/service/codeguruprofiler/generated.json +++ b/service/codeguruprofiler/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codeguruprofiler/go.mod b/service/codeguruprofiler/go.mod index a66066b7cbd..442f1379dd5 100644 --- a/service/codeguruprofiler/go.mod +++ b/service/codeguruprofiler/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codeguruprofiler/internal/endpoints/endpoints.go b/service/codeguruprofiler/internal/endpoints/endpoints.go index ab25ad0fa1a..c073c0da142 100644 --- a/service/codeguruprofiler/internal/endpoints/endpoints.go +++ b/service/codeguruprofiler/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeGuruProfiler endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,165 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-profiler.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-profiler.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-profiler.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-profiler.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-profiler.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeguru-profiler.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-profiler.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeguru-profiler.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-profiler.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-profiler-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-profiler.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/codegurureviewer/api_client.go b/service/codegurureviewer/api_client.go index 45257a33cb5..8845aab8056 100644 --- a/service/codegurureviewer/api_client.go +++ b/service/codegurureviewer/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/codegurureviewer/endpoints.go b/service/codegurureviewer/endpoints.go index 6d5e2d9f739..adeef5e6a4a 100644 --- a/service/codegurureviewer/endpoints.go +++ b/service/codegurureviewer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codegurureviewer/generated.json b/service/codegurureviewer/generated.json index 98d3ee0b805..941351e8f00 100644 --- a/service/codegurureviewer/generated.json +++ b/service/codegurureviewer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/codegurureviewer/go.mod b/service/codegurureviewer/go.mod index 364541a60f4..f99b1b357d0 100644 --- a/service/codegurureviewer/go.mod +++ b/service/codegurureviewer/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codegurureviewer/internal/endpoints/endpoints.go b/service/codegurureviewer/internal/endpoints/endpoints.go index 015d20f2c5b..554f8325bc0 100644 --- a/service/codegurureviewer/internal/endpoints/endpoints.go +++ b/service/codegurureviewer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeGuru Reviewer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,62 +102,165 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-reviewer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-reviewer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-reviewer.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-reviewer.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-reviewer.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeguru-reviewer.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-reviewer.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codeguru-reviewer.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codeguru-reviewer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codeguru-reviewer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codeguru-reviewer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/codepipeline/api_client.go b/service/codepipeline/api_client.go index a72d9876d8d..6c858b8c0be 100644 --- a/service/codepipeline/api_client.go +++ b/service/codepipeline/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/codepipeline/endpoints.go b/service/codepipeline/endpoints.go index d89121b58dc..7883b3ff83f 100644 --- a/service/codepipeline/endpoints.go +++ b/service/codepipeline/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codepipeline/generated.json b/service/codepipeline/generated.json index 0d3578f9f25..b1c5820b1bd 100644 --- a/service/codepipeline/generated.json +++ b/service/codepipeline/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codepipeline/go.mod b/service/codepipeline/go.mod index d1cb5ffe0c4..65d79dc1816 100644 --- a/service/codepipeline/go.mod +++ b/service/codepipeline/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codepipeline/internal/endpoints/endpoints.go b/service/codepipeline/internal/endpoints/endpoints.go index ac052a6cc69..ec58286d4ca 100644 --- a/service/codepipeline/internal/endpoints/endpoints.go +++ b/service/codepipeline/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodePipeline endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,111 +102,286 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codepipeline.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codepipeline.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codepipeline-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codepipeline.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codepipeline.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codepipeline.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codepipeline-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codepipeline.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codepipeline.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codepipeline.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codepipeline.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codepipeline.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codepipeline.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codepipeline.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codepipeline-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codepipeline.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "codepipeline-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codepipeline-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/codestar/api_client.go b/service/codestar/api_client.go index 27572ee08c5..f99d75bb4df 100644 --- a/service/codestar/api_client.go +++ b/service/codestar/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codestar/endpoints.go b/service/codestar/endpoints.go index 0c43ad4bf4b..261fde56d6f 100644 --- a/service/codestar/endpoints.go +++ b/service/codestar/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codestar/generated.json b/service/codestar/generated.json index afc939df783..ff9d1fb5fa1 100644 --- a/service/codestar/generated.json +++ b/service/codestar/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codestar/go.mod b/service/codestar/go.mod index 52fcbc51084..2b78948a141 100644 --- a/service/codestar/go.mod +++ b/service/codestar/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codestar/internal/endpoints/endpoints.go b/service/codestar/internal/endpoints/endpoints.go index 6b51a45195c..d00b0d9fba7 100644 --- a/service/codestar/internal/endpoints/endpoints.go +++ b/service/codestar/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeStar endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,65 +102,174 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codestar.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codestar.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codestar.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codestar.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codestar.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/codestarconnections/api_client.go b/service/codestarconnections/api_client.go index 01ebf258a85..c3a5df55d59 100644 --- a/service/codestarconnections/api_client.go +++ b/service/codestarconnections/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/codestarconnections/endpoints.go b/service/codestarconnections/endpoints.go index 601b004d480..956e5c5f4ea 100644 --- a/service/codestarconnections/endpoints.go +++ b/service/codestarconnections/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codestarconnections/generated.json b/service/codestarconnections/generated.json index 85a193bec07..b9cf0c57752 100644 --- a/service/codestarconnections/generated.json +++ b/service/codestarconnections/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codestarconnections/go.mod b/service/codestarconnections/go.mod index b2cc0e8db02..ac190a06539 100644 --- a/service/codestarconnections/go.mod +++ b/service/codestarconnections/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codestarconnections/internal/endpoints/endpoints.go b/service/codestarconnections/internal/endpoints/endpoints.go index f335bab68cc..53e9aa21aba 100644 --- a/service/codestarconnections/internal/endpoints/endpoints.go +++ b/service/codestarconnections/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver CodeStar connections endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,68 +102,183 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-connections.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-connections-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-connections.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-connections.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-connections-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-connections.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-connections.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar-connections.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-connections.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar-connections.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-connections.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-connections-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-connections-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-connections.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/codestarnotifications/api_client.go b/service/codestarnotifications/api_client.go index 9793fba5d4c..e66b718aeb6 100644 --- a/service/codestarnotifications/api_client.go +++ b/service/codestarnotifications/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/codestarnotifications/endpoints.go b/service/codestarnotifications/endpoints.go index 5059817d157..be82a51f1ea 100644 --- a/service/codestarnotifications/endpoints.go +++ b/service/codestarnotifications/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/codestarnotifications/generated.json b/service/codestarnotifications/generated.json index 572c6f9a13a..df3c7a40620 100644 --- a/service/codestarnotifications/generated.json +++ b/service/codestarnotifications/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/codestarnotifications/go.mod b/service/codestarnotifications/go.mod index 34e9366fb67..c879899bc57 100644 --- a/service/codestarnotifications/go.mod +++ b/service/codestarnotifications/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/codestarnotifications/internal/endpoints/endpoints.go b/service/codestarnotifications/internal/endpoints/endpoints.go index d255631222c..239d823500d 100644 --- a/service/codestarnotifications/internal/endpoints/endpoints.go +++ b/service/codestarnotifications/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver codestar notifications endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,189 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-notifications.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-notifications.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-notifications.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-notifications.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-notifications.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar-notifications.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-notifications.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "codestar-notifications.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "codestar-notifications.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "codestar-notifications-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "codestar-notifications.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/cognitoidentity/api_client.go b/service/cognitoidentity/api_client.go index 2534a9eeebe..6434ca4cd9f 100644 --- a/service/cognitoidentity/api_client.go +++ b/service/cognitoidentity/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cognitoidentity/endpoints.go b/service/cognitoidentity/endpoints.go index d9e0742a172..cbdc4254914 100644 --- a/service/cognitoidentity/endpoints.go +++ b/service/cognitoidentity/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cognitoidentity/generated.json b/service/cognitoidentity/generated.json index d522158734a..16392df9e88 100644 --- a/service/cognitoidentity/generated.json +++ b/service/cognitoidentity/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cognitoidentity/go.mod b/service/cognitoidentity/go.mod index 28dcbaf3bde..d42f4781944 100644 --- a/service/cognitoidentity/go.mod +++ b/service/cognitoidentity/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cognitoidentity/internal/endpoints/endpoints.go b/service/cognitoidentity/internal/endpoints/endpoints.go index 65b01a5119c..9027ad6a051 100644 --- a/service/cognitoidentity/internal/endpoints/endpoints.go +++ b/service/cognitoidentity/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cognito Identity endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,101 +102,258 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-identity.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-identity.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "cognito-identity-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "cognito-identity-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "cognito-identity-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-identity.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-identity.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-identity.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-identity.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-identity.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-identity.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-identity.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-identity-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-identity.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "cognito-identity-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-identity-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/cognitoidentityprovider/api_client.go b/service/cognitoidentityprovider/api_client.go index f0d39cf4ac3..8791df47980 100644 --- a/service/cognitoidentityprovider/api_client.go +++ b/service/cognitoidentityprovider/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cognitoidentityprovider/endpoints.go b/service/cognitoidentityprovider/endpoints.go index ce2ad6a1890..473c125aa94 100644 --- a/service/cognitoidentityprovider/endpoints.go +++ b/service/cognitoidentityprovider/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cognitoidentityprovider/generated.json b/service/cognitoidentityprovider/generated.json index 804af98fd67..cc2243b03d4 100644 --- a/service/cognitoidentityprovider/generated.json +++ b/service/cognitoidentityprovider/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cognitoidentityprovider/go.mod b/service/cognitoidentityprovider/go.mod index 1d8be3a9c19..73c29806976 100644 --- a/service/cognitoidentityprovider/go.mod +++ b/service/cognitoidentityprovider/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cognitoidentityprovider/internal/endpoints/endpoints.go b/service/cognitoidentityprovider/internal/endpoints/endpoints.go index 451b2a4683c..ca4516609be 100644 --- a/service/cognitoidentityprovider/internal/endpoints/endpoints.go +++ b/service/cognitoidentityprovider/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cognito Identity Provider endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,104 +102,268 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-idp.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-idp.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "cognito-idp-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "cognito-idp-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "cognito-idp-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "cognito-idp-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-idp.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-idp.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-idp.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-idp.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-idp.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-idp.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-idp.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-idp-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-idp.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "cognito-idp-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-idp-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/cognitosync/api_client.go b/service/cognitosync/api_client.go index 8f2bf194931..63ca336623c 100644 --- a/service/cognitosync/api_client.go +++ b/service/cognitosync/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/cognitosync/endpoints.go b/service/cognitosync/endpoints.go index 4cfbe245d4a..7849427e1e7 100644 --- a/service/cognitosync/endpoints.go +++ b/service/cognitosync/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/cognitosync/generated.json b/service/cognitosync/generated.json index 69e470c50de..e27b0536e21 100644 --- a/service/cognitosync/generated.json +++ b/service/cognitosync/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/cognitosync/go.mod b/service/cognitosync/go.mod index 3b95479abec..998ff78ae4b 100644 --- a/service/cognitosync/go.mod +++ b/service/cognitosync/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/cognitosync/internal/endpoints/endpoints.go b/service/cognitosync/internal/endpoints/endpoints.go index 66418eb2a3e..c32f336ed7c 100644 --- a/service/cognitosync/internal/endpoints/endpoints.go +++ b/service/cognitosync/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cognito Sync endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,168 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-sync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-sync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-sync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-sync.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-sync-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-sync.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-sync.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-sync.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-sync.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cognito-sync.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cognito-sync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cognito-sync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cognito-sync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cognito-sync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/comprehend/api_client.go b/service/comprehend/api_client.go index 5b46cd17f8e..89b1e05d916 100644 --- a/service/comprehend/api_client.go +++ b/service/comprehend/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/comprehend/endpoints.go b/service/comprehend/endpoints.go index 5b5dc0960e4..15dcc781c56 100644 --- a/service/comprehend/endpoints.go +++ b/service/comprehend/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/comprehend/generated.json b/service/comprehend/generated.json index ee494942534..9ae70b5f0d3 100644 --- a/service/comprehend/generated.json +++ b/service/comprehend/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/comprehend/go.mod b/service/comprehend/go.mod index e7cd3c1ad16..22cae35c851 100644 --- a/service/comprehend/go.mod +++ b/service/comprehend/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/comprehend/internal/endpoints/endpoints.go b/service/comprehend/internal/endpoints/endpoints.go index f10e610913f..a16686e73c8 100644 --- a/service/comprehend/internal/endpoints/endpoints.go +++ b/service/comprehend/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Comprehend endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,96 +102,243 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "comprehend.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehend.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehend-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehend.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "comprehend-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "comprehend-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "comprehend-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "comprehend.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehend.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehend-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehend.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "comprehend.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "comprehend.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "comprehend.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "comprehend.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "comprehend.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehend.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehend-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehend.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "comprehend-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehend-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/comprehendmedical/api_client.go b/service/comprehendmedical/api_client.go index ed0874697ce..7b19c8cdea5 100644 --- a/service/comprehendmedical/api_client.go +++ b/service/comprehendmedical/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/comprehendmedical/endpoints.go b/service/comprehendmedical/endpoints.go index 0d9460f4383..ae3956dda22 100644 --- a/service/comprehendmedical/endpoints.go +++ b/service/comprehendmedical/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/comprehendmedical/generated.json b/service/comprehendmedical/generated.json index 4ace1874818..6c7b6730dc8 100644 --- a/service/comprehendmedical/generated.json +++ b/service/comprehendmedical/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/comprehendmedical/go.mod b/service/comprehendmedical/go.mod index da2c41765d7..492b3435069 100644 --- a/service/comprehendmedical/go.mod +++ b/service/comprehendmedical/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/comprehendmedical/internal/endpoints/endpoints.go b/service/comprehendmedical/internal/endpoints/endpoints.go index 378c4f4c843..3cab94f4f6e 100644 --- a/service/comprehendmedical/internal/endpoints/endpoints.go +++ b/service/comprehendmedical/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ComprehendMedical endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,88 +102,223 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "comprehendmedical.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehendmedical.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "comprehendmedical-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "comprehendmedical-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "comprehendmedical-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "comprehendmedical.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehendmedical.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "comprehendmedical.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "comprehendmedical.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "comprehendmedical.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "comprehendmedical.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "comprehendmedical.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "comprehendmedical-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "comprehendmedical.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "comprehendmedical-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "comprehendmedical-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/computeoptimizer/api_client.go b/service/computeoptimizer/api_client.go index 8b2294d100a..26d39c73624 100644 --- a/service/computeoptimizer/api_client.go +++ b/service/computeoptimizer/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/computeoptimizer/endpoints.go b/service/computeoptimizer/endpoints.go index 75691f640bc..e7d1de9693f 100644 --- a/service/computeoptimizer/endpoints.go +++ b/service/computeoptimizer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/computeoptimizer/generated.json b/service/computeoptimizer/generated.json index 18c8f388ccf..4d1941a4c09 100644 --- a/service/computeoptimizer/generated.json +++ b/service/computeoptimizer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/computeoptimizer/go.mod b/service/computeoptimizer/go.mod index 4c351cddf8d..5c0b12be3a2 100644 --- a/service/computeoptimizer/go.mod +++ b/service/computeoptimizer/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/computeoptimizer/internal/endpoints/endpoints.go b/service/computeoptimizer/internal/endpoints/endpoints.go index 0277364574e..c3050580918 100644 --- a/service/computeoptimizer/internal/endpoints/endpoints.go +++ b/service/computeoptimizer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Compute Optimizer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,281 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "compute-optimizer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "compute-optimizer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ap-northeast-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ap-northeast-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ap-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ap-southeast-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ap-southeast-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.eu-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.eu-north-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.eu-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.eu-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.eu-west-3.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-3", + }, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.sa-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "sa-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "compute-optimizer.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "compute-optimizer.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.cn-north-1.amazonaws.com.cn", + CredentialScope: endpoints.CredentialScope{ + Region: "cn-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ + Hostname: "compute-optimizer.cn-northwest-1.amazonaws.com.cn", + CredentialScope: endpoints.CredentialScope{ + Region: "cn-northwest-1", + }, + }, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "compute-optimizer.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "compute-optimizer.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "compute-optimizer.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "compute-optimizer.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "compute-optimizer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "compute-optimizer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "compute-optimizer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/configservice/api_client.go b/service/configservice/api_client.go index b152bbbfa37..686ea0efcd3 100644 --- a/service/configservice/api_client.go +++ b/service/configservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/configservice/endpoints.go b/service/configservice/endpoints.go index a06debd5429..188b66910b1 100644 --- a/service/configservice/endpoints.go +++ b/service/configservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/configservice/generated.json b/service/configservice/generated.json index b7e23312df4..838f08bc40e 100644 --- a/service/configservice/generated.json +++ b/service/configservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/configservice/go.mod b/service/configservice/go.mod index 0d24825268b..8e3b405f671 100644 --- a/service/configservice/go.mod +++ b/service/configservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/configservice/internal/endpoints/endpoints.go b/service/configservice/internal/endpoints/endpoints.go index 044b3df96ce..3cfe753c594 100644 --- a/service/configservice/internal/endpoints/endpoints.go +++ b/service/configservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Config Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "config-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "config-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "config-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "config-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "config.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "config.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "config-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "config.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "config.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "config.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "config.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "config.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "config.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "config.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "config.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/connect/api_client.go b/service/connect/api_client.go index 3fdb1650b8b..6cab298ec96 100644 --- a/service/connect/api_client.go +++ b/service/connect/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/connect/endpoints.go b/service/connect/endpoints.go index 15c6ef350e7..46e51908bf5 100644 --- a/service/connect/endpoints.go +++ b/service/connect/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/connect/generated.json b/service/connect/generated.json index bb2937a6018..a58a7d06dc8 100644 --- a/service/connect/generated.json +++ b/service/connect/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/connect/go.mod b/service/connect/go.mod index c753d83eeff..4df9911e283 100644 --- a/service/connect/go.mod +++ b/service/connect/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/connect/internal/endpoints/endpoints.go b/service/connect/internal/endpoints/endpoints.go index 371f57361df..2fdf3f60b26 100644 --- a/service/connect/internal/endpoints/endpoints.go +++ b/service/connect/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Connect endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,65 +102,166 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "connect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "connect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "connect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "connect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "connect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "connect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "connect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "connect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "connect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/connectcontactlens/api_client.go b/service/connectcontactlens/api_client.go index af82b7592ff..2b9accbb2a0 100644 --- a/service/connectcontactlens/api_client.go +++ b/service/connectcontactlens/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/connectcontactlens/endpoints.go b/service/connectcontactlens/endpoints.go index a654bf0efa3..c28cd24e6b1 100644 --- a/service/connectcontactlens/endpoints.go +++ b/service/connectcontactlens/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/connectcontactlens/generated.json b/service/connectcontactlens/generated.json index 135dd6d07d8..0c6a61dfafd 100644 --- a/service/connectcontactlens/generated.json +++ b/service/connectcontactlens/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/connectcontactlens/go.mod b/service/connectcontactlens/go.mod index 5f8a78c57d7..18b689e70a4 100644 --- a/service/connectcontactlens/go.mod +++ b/service/connectcontactlens/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/connectcontactlens/internal/endpoints/endpoints.go b/service/connectcontactlens/internal/endpoints/endpoints.go index 6c8f38438dc..411c9611c16 100644 --- a/service/connectcontactlens/internal/endpoints/endpoints.go +++ b/service/connectcontactlens/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Connect Contact Lens endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "contact-lens.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "contact-lens.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "contact-lens-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "contact-lens-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "contact-lens.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "contact-lens.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "contact-lens.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "contact-lens-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "contact-lens-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "contact-lens.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "contact-lens.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "contact-lens.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "contact-lens.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "contact-lens.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "contact-lens.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "contact-lens.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "contact-lens-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "contact-lens-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "contact-lens.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/connectparticipant/api_client.go b/service/connectparticipant/api_client.go index 3a60d8f6027..0640e069957 100644 --- a/service/connectparticipant/api_client.go +++ b/service/connectparticipant/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/connectparticipant/endpoints.go b/service/connectparticipant/endpoints.go index ed35d3f7d38..f1344407449 100644 --- a/service/connectparticipant/endpoints.go +++ b/service/connectparticipant/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/connectparticipant/generated.json b/service/connectparticipant/generated.json index 4208f5d102e..19809d4f1b3 100644 --- a/service/connectparticipant/generated.json +++ b/service/connectparticipant/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/connectparticipant/go.mod b/service/connectparticipant/go.mod index c049c166011..f7b1efe38a7 100644 --- a/service/connectparticipant/go.mod +++ b/service/connectparticipant/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/connectparticipant/internal/endpoints/endpoints.go b/service/connectparticipant/internal/endpoints/endpoints.go index ed9a038e8e3..02989ad283d 100644 --- a/service/connectparticipant/internal/endpoints/endpoints.go +++ b/service/connectparticipant/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ConnectParticipant endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "participant.connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "participant.connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "participant.connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "participant.connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "participant.connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "participant.connect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "participant.connect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "participant.connect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "participant.connect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "participant.connect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "participant.connect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "participant.connect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "participant.connect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "participant.connect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "participant.connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "participant.connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "participant.connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "participant.connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "participant.connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/costandusagereportservice/api_client.go b/service/costandusagereportservice/api_client.go index 2bce50fbbf9..6758a1079ff 100644 --- a/service/costandusagereportservice/api_client.go +++ b/service/costandusagereportservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/costandusagereportservice/endpoints.go b/service/costandusagereportservice/endpoints.go index cebf0b01465..7e20b984fe1 100644 --- a/service/costandusagereportservice/endpoints.go +++ b/service/costandusagereportservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/costandusagereportservice/generated.json b/service/costandusagereportservice/generated.json index fe03c60378b..8044b6aa0b5 100644 --- a/service/costandusagereportservice/generated.json +++ b/service/costandusagereportservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/costandusagereportservice/go.mod b/service/costandusagereportservice/go.mod index 86c2c366497..4ddcb5926aa 100644 --- a/service/costandusagereportservice/go.mod +++ b/service/costandusagereportservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/costandusagereportservice/internal/endpoints/endpoints.go b/service/costandusagereportservice/internal/endpoints/endpoints.go index e4e9fb51af7..27afcfe456d 100644 --- a/service/costandusagereportservice/internal/endpoints/endpoints.go +++ b/service/costandusagereportservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cost and Usage Report Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,56 +102,143 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "cur.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cur.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cur-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cur-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cur.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "cur.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cur.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cur-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cur-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cur.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "cur.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cur.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "cur.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "cur.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "cur.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "cur.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "cur-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "cur-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "cur.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/costexplorer/api_client.go b/service/costexplorer/api_client.go index b01440b6f8e..9d4d533077e 100644 --- a/service/costexplorer/api_client.go +++ b/service/costexplorer/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/costexplorer/endpoints.go b/service/costexplorer/endpoints.go index 933b77f4c63..33b9ba12f26 100644 --- a/service/costexplorer/endpoints.go +++ b/service/costexplorer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/costexplorer/generated.json b/service/costexplorer/generated.json index b2bd04e8ce6..51f607e969e 100644 --- a/service/costexplorer/generated.json +++ b/service/costexplorer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/costexplorer/go.mod b/service/costexplorer/go.mod index eadda30d78b..b157c84969f 100644 --- a/service/costexplorer/go.mod +++ b/service/costexplorer/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/costexplorer/internal/endpoints/endpoints.go b/service/costexplorer/internal/endpoints/endpoints.go index 4d6bb582d1f..7b6e15ede20 100644 --- a/service/costexplorer/internal/endpoints/endpoints.go +++ b/service/costexplorer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Cost Explorer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ce.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ce.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ce-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ce-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ce.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "ce.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -74,16 +148,43 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ce.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ce.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ce-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ce-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ce.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "ce.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -93,30 +194,63 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ce.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ce.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ce.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ce.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ce.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ce.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ce-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ce-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ce.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/customerprofiles/api_client.go b/service/customerprofiles/api_client.go index 661d44106b5..478133143ce 100644 --- a/service/customerprofiles/api_client.go +++ b/service/customerprofiles/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/customerprofiles/endpoints.go b/service/customerprofiles/endpoints.go index 145b76ac8ce..eb07e30e00c 100644 --- a/service/customerprofiles/endpoints.go +++ b/service/customerprofiles/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/customerprofiles/generated.json b/service/customerprofiles/generated.json index 93d6381c679..b7b4a9831ae 100644 --- a/service/customerprofiles/generated.json +++ b/service/customerprofiles/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/customerprofiles/go.mod b/service/customerprofiles/go.mod index 21c8d3700a8..1d13237c4ae 100644 --- a/service/customerprofiles/go.mod +++ b/service/customerprofiles/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/customerprofiles/internal/endpoints/endpoints.go b/service/customerprofiles/internal/endpoints/endpoints.go index 56fcb850c18..fbfdf169345 100644 --- a/service/customerprofiles/internal/endpoints/endpoints.go +++ b/service/customerprofiles/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Customer Profiles endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,60 +102,159 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "profile.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "profile.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "profile-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "profile-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "profile.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "profile.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "profile.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "profile-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "profile-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "profile.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "profile.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "profile.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "profile.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "profile.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "profile.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "profile.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "profile-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "profile-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "profile.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/databasemigrationservice/api_client.go b/service/databasemigrationservice/api_client.go index eb1d8a1d17d..cf2cdd66818 100644 --- a/service/databasemigrationservice/api_client.go +++ b/service/databasemigrationservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/databasemigrationservice/endpoints.go b/service/databasemigrationservice/endpoints.go index 15f95373576..8504b223c37 100644 --- a/service/databasemigrationservice/endpoints.go +++ b/service/databasemigrationservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/databasemigrationservice/generated.json b/service/databasemigrationservice/generated.json index f0da7859ab8..1f4d88b36a7 100644 --- a/service/databasemigrationservice/generated.json +++ b/service/databasemigrationservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/databasemigrationservice/go.mod b/service/databasemigrationservice/go.mod index f4a5a0d4151..0068d756232 100644 --- a/service/databasemigrationservice/go.mod +++ b/service/databasemigrationservice/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/databasemigrationservice/internal/endpoints/endpoints.go b/service/databasemigrationservice/internal/endpoints/endpoints.go index 6dd5ff8cb37..4d681d5680a 100644 --- a/service/databasemigrationservice/internal/endpoints/endpoints.go +++ b/service/databasemigrationservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Database Migration Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,113 +102,334 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "dms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "dms-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "dms", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dms", + Variant: endpoints.FIPSVariant, + }: { Hostname: "dms-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "dms-fips", + }: endpoints.Endpoint{ + Hostname: "dms-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "dms.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dms.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dms-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dms-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dms.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "dms.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dms.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "dms-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dms", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-iso-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dms", + Variant: endpoints.FIPSVariant, + }: { Hostname: "dms.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "dms-fips", + }: endpoints.Endpoint{ + Hostname: "dms.us-iso-east-1.c2s.ic.gov", + CredentialScope: endpoints.CredentialScope{ + Region: "us-iso-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "dms.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dms.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "dms-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dms", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-isob-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dms", + Variant: endpoints.FIPSVariant, + }: { Hostname: "dms.us-isob-east-1.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "dms-fips", + }: endpoints.Endpoint{ + Hostname: "dms.us-isob-east-1.sc2s.sgov.gov", + CredentialScope: endpoints.CredentialScope{ + Region: "us-isob-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "dms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "dms-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dms", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dms", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dms.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dms-fips", + }: endpoints.Endpoint{ Hostname: "dms.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/databrew/api_client.go b/service/databrew/api_client.go index 69f6bb49666..8bb845da8ad 100644 --- a/service/databrew/api_client.go +++ b/service/databrew/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/databrew/endpoints.go b/service/databrew/endpoints.go index e0c17c84c06..8459489f56a 100644 --- a/service/databrew/endpoints.go +++ b/service/databrew/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/databrew/generated.json b/service/databrew/generated.json index e5808d746bc..24c59feb51c 100644 --- a/service/databrew/generated.json +++ b/service/databrew/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/databrew/go.mod b/service/databrew/go.mod index 72f8627d28d..cdff7bcfa30 100644 --- a/service/databrew/go.mod +++ b/service/databrew/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/databrew/internal/endpoints/endpoints.go b/service/databrew/internal/endpoints/endpoints.go index e3b07f84bef..a91e2d0935c 100644 --- a/service/databrew/internal/endpoints/endpoints.go +++ b/service/databrew/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DataBrew endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,207 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "databrew.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "databrew.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "databrew-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "databrew-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "databrew.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "databrew.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "databrew.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "databrew-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "databrew-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "databrew.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "databrew.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "databrew.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "databrew.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "databrew.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "databrew.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "databrew.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "databrew-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "databrew-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "databrew.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/dataexchange/api_client.go b/service/dataexchange/api_client.go index bd68cf2a242..c6a266293bf 100644 --- a/service/dataexchange/api_client.go +++ b/service/dataexchange/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/dataexchange/endpoints.go b/service/dataexchange/endpoints.go index b8914f51722..fa7a8c5bef2 100644 --- a/service/dataexchange/endpoints.go +++ b/service/dataexchange/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/dataexchange/generated.json b/service/dataexchange/generated.json index 573c9d6c8bd..94b862d8368 100644 --- a/service/dataexchange/generated.json +++ b/service/dataexchange/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/dataexchange/go.mod b/service/dataexchange/go.mod index 9a0fb4126e5..b6fbc28c678 100644 --- a/service/dataexchange/go.mod +++ b/service/dataexchange/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/dataexchange/internal/endpoints/endpoints.go b/service/dataexchange/internal/endpoints/endpoints.go index d8bf505936a..6b5455c2717 100644 --- a/service/dataexchange/internal/endpoints/endpoints.go +++ b/service/dataexchange/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DataExchange endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,168 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "dataexchange.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dataexchange.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dataexchange-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dataexchange-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dataexchange.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "dataexchange.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dataexchange.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dataexchange-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dataexchange-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dataexchange.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "dataexchange.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dataexchange.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "dataexchange.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dataexchange.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "dataexchange.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dataexchange.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dataexchange-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dataexchange-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dataexchange.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/datapipeline/api_client.go b/service/datapipeline/api_client.go index c448dfdc0e3..a63a5e58c96 100644 --- a/service/datapipeline/api_client.go +++ b/service/datapipeline/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/datapipeline/endpoints.go b/service/datapipeline/endpoints.go index 22d12f05bc7..04bf3b253b1 100644 --- a/service/datapipeline/endpoints.go +++ b/service/datapipeline/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/datapipeline/generated.json b/service/datapipeline/generated.json index 2cd6d13f467..675ca0bedee 100644 --- a/service/datapipeline/generated.json +++ b/service/datapipeline/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/datapipeline/go.mod b/service/datapipeline/go.mod index 9b7539efc2f..f7942b4ff8b 100644 --- a/service/datapipeline/go.mod +++ b/service/datapipeline/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/datapipeline/internal/endpoints/endpoints.go b/service/datapipeline/internal/endpoints/endpoints.go index e6494bd00a8..ec1e1e325eb 100644 --- a/service/datapipeline/internal/endpoints/endpoints.go +++ b/service/datapipeline/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Data Pipeline endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,60 +102,155 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "datapipeline.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datapipeline.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datapipeline-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datapipeline-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datapipeline.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "datapipeline.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datapipeline.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datapipeline-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datapipeline-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datapipeline.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "datapipeline.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "datapipeline.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "datapipeline.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "datapipeline.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "datapipeline.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datapipeline.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datapipeline-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datapipeline-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datapipeline.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/datasync/api_client.go b/service/datasync/api_client.go index 3e7e95bffa5..973aba70435 100644 --- a/service/datasync/api_client.go +++ b/service/datasync/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/datasync/endpoints.go b/service/datasync/endpoints.go index 4d2a442a9bd..c1d61d42951 100644 --- a/service/datasync/endpoints.go +++ b/service/datasync/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/datasync/generated.json b/service/datasync/generated.json index 16132dbea42..e726465e223 100644 --- a/service/datasync/generated.json +++ b/service/datasync/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/datasync/go.mod b/service/datasync/go.mod index c3ac65411c9..3cc430b1d13 100644 --- a/service/datasync/go.mod +++ b/service/datasync/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/datasync/internal/endpoints/endpoints.go b/service/datasync/internal/endpoints/endpoints.go index c9e5f0152ba..fedebe9109c 100644 --- a/service/datasync/internal/endpoints/endpoints.go +++ b/service/datasync/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DataSync endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,313 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "datasync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datasync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datasync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datasync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "datasync-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "datasync.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datasync.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datasync-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datasync.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "datasync.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "datasync.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "datasync.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "datasync.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "datasync.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "datasync.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "datasync-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "datasync.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "datasync-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "datasync-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/dax/api_client.go b/service/dax/api_client.go index 05ae01f7357..4ada4e3f4c8 100644 --- a/service/dax/api_client.go +++ b/service/dax/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/dax/endpoints.go b/service/dax/endpoints.go index 088a46fcfe8..e486bb9cf28 100644 --- a/service/dax/endpoints.go +++ b/service/dax/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/dax/generated.json b/service/dax/generated.json index 347c49af62e..a369e7af275 100644 --- a/service/dax/generated.json +++ b/service/dax/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/dax/go.mod b/service/dax/go.mod index bd5c98a9c7f..d34392bf57c 100644 --- a/service/dax/go.mod +++ b/service/dax/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/dax/internal/endpoints/endpoints.go b/service/dax/internal/endpoints/endpoints.go index 0422dd8cdfb..fdf6136e404 100644 --- a/service/dax/internal/endpoints/endpoints.go +++ b/service/dax/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DAX endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,182 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "dax.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dax.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dax-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dax-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dax.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "dax.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dax.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dax-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dax-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dax.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "dax.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dax.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "dax.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dax.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "dax.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dax.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dax-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dax-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dax.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/detective/api_client.go b/service/detective/api_client.go index f9f9c66825c..b0d0d9453dc 100644 --- a/service/detective/api_client.go +++ b/service/detective/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/detective/endpoints.go b/service/detective/endpoints.go index 9af8e8e2877..53a53dc26fd 100644 --- a/service/detective/endpoints.go +++ b/service/detective/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/detective/generated.json b/service/detective/generated.json index f5facb79698..f42da41c41d 100644 --- a/service/detective/generated.json +++ b/service/detective/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/detective/go.mod b/service/detective/go.mod index dec3c81b46e..b0233c4f29c 100644 --- a/service/detective/go.mod +++ b/service/detective/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/detective/internal/endpoints/endpoints.go b/service/detective/internal/endpoints/endpoints.go index 9fbd5ecf372..a5c1edc1ae3 100644 --- a/service/detective/internal/endpoints/endpoints.go +++ b/service/detective/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Detective endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,113 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.detective.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.detective.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.detective-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.detective.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.detective.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.detective.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.detective-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.detective.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.detective.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.detective.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.detective.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.detective.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.detective.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.detective.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.detective-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.detective.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.detective-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "api.detective-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/devicefarm/api_client.go b/service/devicefarm/api_client.go index a41be49a217..86858e5da1b 100644 --- a/service/devicefarm/api_client.go +++ b/service/devicefarm/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/devicefarm/endpoints.go b/service/devicefarm/endpoints.go index a8bba601a42..3c4db44971f 100644 --- a/service/devicefarm/endpoints.go +++ b/service/devicefarm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/devicefarm/generated.json b/service/devicefarm/generated.json index 24dc6ed9bf5..2813020fc41 100644 --- a/service/devicefarm/generated.json +++ b/service/devicefarm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/devicefarm/go.mod b/service/devicefarm/go.mod index 0e190725271..dabd7269d09 100644 --- a/service/devicefarm/go.mod +++ b/service/devicefarm/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/devicefarm/internal/endpoints/endpoints.go b/service/devicefarm/internal/endpoints/endpoints.go index 40073ae13fe..fb898e2c0d4 100644 --- a/service/devicefarm/internal/endpoints/endpoints.go +++ b/service/devicefarm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Device Farm endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,53 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "devicefarm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devicefarm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devicefarm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devicefarm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devicefarm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "devicefarm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devicefarm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devicefarm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devicefarm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devicefarm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "devicefarm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devicefarm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "devicefarm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devicefarm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "devicefarm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devicefarm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devicefarm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devicefarm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devicefarm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/devopsguru/api_client.go b/service/devopsguru/api_client.go index 1ef0d07b1e4..fc631fe698a 100644 --- a/service/devopsguru/api_client.go +++ b/service/devopsguru/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/devopsguru/endpoints.go b/service/devopsguru/endpoints.go index 202b0b0da51..68e179ac5a4 100644 --- a/service/devopsguru/endpoints.go +++ b/service/devopsguru/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/devopsguru/generated.json b/service/devopsguru/generated.json index 89b4944cabb..5ccb3268377 100644 --- a/service/devopsguru/generated.json +++ b/service/devopsguru/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/devopsguru/go.mod b/service/devopsguru/go.mod index 272a1a8eddd..add3f440580 100644 --- a/service/devopsguru/go.mod +++ b/service/devopsguru/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/devopsguru/internal/endpoints/endpoints.go b/service/devopsguru/internal/endpoints/endpoints.go index f2e191cb49c..cb26fe71c6e 100644 --- a/service/devopsguru/internal/endpoints/endpoints.go +++ b/service/devopsguru/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DevOps Guru endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "devops-guru.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devops-guru.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devops-guru-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devops-guru-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devops-guru.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "devops-guru.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devops-guru.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devops-guru-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devops-guru-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devops-guru.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "devops-guru.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devops-guru.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "devops-guru.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devops-guru.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "devops-guru.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devops-guru.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devops-guru-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devops-guru-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devops-guru.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/directconnect/api_client.go b/service/directconnect/api_client.go index b5a154159d8..3cb106d6a51 100644 --- a/service/directconnect/api_client.go +++ b/service/directconnect/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/directconnect/endpoints.go b/service/directconnect/endpoints.go index f708a7ef3e7..41621e8044b 100644 --- a/service/directconnect/endpoints.go +++ b/service/directconnect/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/directconnect/generated.json b/service/directconnect/generated.json index 180d33a8517..2f887aed0c2 100644 --- a/service/directconnect/generated.json +++ b/service/directconnect/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/directconnect/go.mod b/service/directconnect/go.mod index 6eebedc171f..c98e74574d8 100644 --- a/service/directconnect/go.mod +++ b/service/directconnect/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/directconnect/internal/endpoints/endpoints.go b/service/directconnect/internal/endpoints/endpoints.go index ba074f68e4c..fe61098e740 100644 --- a/service/directconnect/internal/endpoints/endpoints.go +++ b/service/directconnect/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Direct Connect endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "directconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "directconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "directconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "directconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "directconnect-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "directconnect-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "directconnect-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "directconnect-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "directconnect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "directconnect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "directconnect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "directconnect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "directconnect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "directconnect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "directconnect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "directconnect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "directconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "directconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "directconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "directconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "directconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "directconnect.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "directconnect.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/directoryservice/api_client.go b/service/directoryservice/api_client.go index 5ab65e7f756..99e3d55fb3f 100644 --- a/service/directoryservice/api_client.go +++ b/service/directoryservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/directoryservice/endpoints.go b/service/directoryservice/endpoints.go index c16be952cc0..094472d9639 100644 --- a/service/directoryservice/endpoints.go +++ b/service/directoryservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/directoryservice/generated.json b/service/directoryservice/generated.json index 1e892ee31f2..47cbbe8885f 100644 --- a/service/directoryservice/generated.json +++ b/service/directoryservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/directoryservice/go.mod b/service/directoryservice/go.mod index 138b184c135..60f7310f8f2 100644 --- a/service/directoryservice/go.mod +++ b/service/directoryservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/directoryservice/internal/endpoints/endpoints.go b/service/directoryservice/internal/endpoints/endpoints.go index 05a31d21270..9e3a3fcec79 100644 --- a/service/directoryservice/internal/endpoints/endpoints.go +++ b/service/directoryservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Directory Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,131 +102,331 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "ds-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ds.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ds.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ds-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ds.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ds.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ds.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ds.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ds.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ds-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ds-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/dlm/api_client.go b/service/dlm/api_client.go index 5018eaf316e..2afeb943bbf 100644 --- a/service/dlm/api_client.go +++ b/service/dlm/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/dlm/endpoints.go b/service/dlm/endpoints.go index f6753694dd6..de77487a247 100644 --- a/service/dlm/endpoints.go +++ b/service/dlm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/dlm/generated.json b/service/dlm/generated.json index 02fecf7da08..7a2a963307b 100644 --- a/service/dlm/generated.json +++ b/service/dlm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/dlm/go.mod b/service/dlm/go.mod index 55ebbfb96a1..a09a4272de0 100644 --- a/service/dlm/go.mod +++ b/service/dlm/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/dlm/internal/endpoints/endpoints.go b/service/dlm/internal/endpoints/endpoints.go index e0f137b2abd..3f3dcea1775 100644 --- a/service/dlm/internal/endpoints/endpoints.go +++ b/service/dlm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DLM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,216 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "dlm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dlm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dlm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dlm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dlm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "dlm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dlm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dlm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dlm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dlm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "dlm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dlm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "dlm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dlm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "dlm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dlm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dlm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dlm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dlm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + }, }, } diff --git a/service/docdb/api_client.go b/service/docdb/api_client.go index f4b280f3242..b7784b2392a 100644 --- a/service/docdb/api_client.go +++ b/service/docdb/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -127,6 +128,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -176,6 +179,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -204,7 +209,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -246,6 +251,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/docdb/endpoints.go b/service/docdb/endpoints.go index 09c34db7832..80c29995ef9 100644 --- a/service/docdb/endpoints.go +++ b/service/docdb/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/docdb/generated.json b/service/docdb/generated.json index 7e53ca35824..c695f9c23ee 100644 --- a/service/docdb/generated.json +++ b/service/docdb/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" diff --git a/service/docdb/go.mod b/service/docdb/go.mod index d7dfa141181..9cf8e5d43d0 100644 --- a/service/docdb/go.mod +++ b/service/docdb/go.mod @@ -4,6 +4,8 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 @@ -11,4 +13,8 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/docdb/internal/endpoints/endpoints.go b/service/docdb/internal/endpoints/endpoints.go index b5ef858a559..5ccd88c7672 100644 --- a/service/docdb/internal/endpoints/endpoints.go +++ b/service/docdb/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DocDB endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,132 +102,380 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "rds-fips.ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "rds-fips.ca-central-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "rds.us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "rds.us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/dynamodb/api_client.go b/service/dynamodb/api_client.go index e39e75b637a..fe930f645e1 100644 --- a/service/dynamodb/api_client.go +++ b/service/dynamodb/api_client.go @@ -157,6 +157,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -207,6 +209,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -235,7 +239,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -299,6 +303,36 @@ func resolveEnableEndpointDiscoveryFromConfigSources(cfg aws.Config, o *Options) return nil } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // resolves endpoint cache on client func resolveEndpointCache(c *Client) { c.endpointCache = internalEndpointDiscovery.NewEndpointCache(10) diff --git a/service/dynamodb/endpoints.go b/service/dynamodb/endpoints.go index a092fa13ab9..ad01a535e73 100644 --- a/service/dynamodb/endpoints.go +++ b/service/dynamodb/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/dynamodb/generated.json b/service/dynamodb/generated.json index d803e87ea5a..eea6c9c46bd 100644 --- a/service/dynamodb/generated.json +++ b/service/dynamodb/generated.json @@ -2,6 +2,7 @@ "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding": "v1.0.5", "github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery": "v0.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", diff --git a/service/dynamodb/go.mod b/service/dynamodb/go.mod index 36809702121..ada676e06e8 100644 --- a/service/dynamodb/go.mod +++ b/service/dynamodb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.4.0 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.2.0 github.com/aws/smithy-go v1.8.1 @@ -15,6 +16,8 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ diff --git a/service/dynamodb/internal/endpoints/endpoints.go b/service/dynamodb/internal/endpoints/endpoints.go index e43331903f9..5551f3d0df3 100644 --- a/service/dynamodb/internal/endpoints/endpoints.go +++ b/service/dynamodb/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DynamoDB endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,140 +102,344 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "dynamodb.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dynamodb.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dynamodb-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dynamodb.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "ca-central-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "local": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "local", + }: endpoints.Endpoint{ Hostname: "localhost:8000", Protocols: []string{"http"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.us-west-1.amazonaws.com", }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "dynamodb.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dynamodb.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dynamodb-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dynamodb.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "dynamodb.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dynamodb.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "dynamodb.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "dynamodb.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "dynamodb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "dynamodb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "dynamodb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "dynamodb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "dynamodb.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "dynamodb.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/dynamodbstreams/api_client.go b/service/dynamodbstreams/api_client.go index 0863232a9ca..4af61ec29a7 100644 --- a/service/dynamodbstreams/api_client.go +++ b/service/dynamodbstreams/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/dynamodbstreams/endpoints.go b/service/dynamodbstreams/endpoints.go index ee013cad880..291ffa498ee 100644 --- a/service/dynamodbstreams/endpoints.go +++ b/service/dynamodbstreams/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/dynamodbstreams/generated.json b/service/dynamodbstreams/generated.json index 03c95f60c5d..211e3bbc6a3 100644 --- a/service/dynamodbstreams/generated.json +++ b/service/dynamodbstreams/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/dynamodbstreams/go.mod b/service/dynamodbstreams/go.mod index e5430321a8b..8074065e49c 100644 --- a/service/dynamodbstreams/go.mod +++ b/service/dynamodbstreams/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/dynamodbstreams/internal/endpoints/endpoints.go b/service/dynamodbstreams/internal/endpoints/endpoints.go index bacb575b8e3..c7250ecfe35 100644 --- a/service/dynamodbstreams/internal/endpoints/endpoints.go +++ b/service/dynamodbstreams/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver DynamoDB Streams endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,150 +102,297 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "streams.dynamodb.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "dynamodb", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, }, - }, - RegionRegex: partitionRegexp.Aws, - IsRegionalized: true, - Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "ca-central-1-fips": endpoints.Endpoint{ - Hostname: "dynamodb-fips.ca-central-1.amazonaws.com", + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "ca-central-1", + Service: "dynamodb", }, }, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "local": endpoints.Endpoint{ - Hostname: "localhost:8000", - Protocols: []string{"http"}, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "us-east-1", + Service: "dynamodb", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ - Hostname: "dynamodb-fips.us-east-1.amazonaws.com", + { + Variant: 0, + }: { + Hostname: "streams.dynamodb.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "us-east-1", + Service: "dynamodb", }, }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ - Hostname: "dynamodb-fips.us-east-2.amazonaws.com", + }, + RegionRegex: partitionRegexp.Aws, + IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, + }, + { + ID: "aws-cn", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "us-east-2", + Service: "dynamodb", }, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ - Hostname: "dynamodb-fips.us-west-1.amazonaws.com", + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "us-west-1", + Service: "dynamodb", }, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ - Hostname: "dynamodb-fips.us-west-2.amazonaws.com", + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, CredentialScope: endpoints.CredentialScope{ - Region: "us-west-2", + Service: "dynamodb", }, }, - }, - }, - { - ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "streams.dynamodb.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "dynamodb", + { + Variant: 0, + }: { + Hostname: "streams.dynamodb.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "streams.dynamodb.{region}.c2s.ic.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "dynamodb", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "streams.dynamodb.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ - Protocols: []string{"http", "https"}, - }, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "streams.dynamodb.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "dynamodb", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "streams.dynamodb.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "streams.dynamodb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "dynamodb", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "streams.dynamodb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, + }, + { + Variant: 0, + }: { + Hostname: "streams.dynamodb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "dynamodb", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ - Hostname: "dynamodb.us-gov-east-1.amazonaws.com", + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "streams.dynamodb.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ + Hostname: "streams.dynamodb.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "streams.dynamodb.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ - Hostname: "dynamodb.us-gov-west-1.amazonaws.com", + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ + Hostname: "streams.dynamodb.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/ebs/api_client.go b/service/ebs/api_client.go index 54a7e830e99..658e504922f 100644 --- a/service/ebs/api_client.go +++ b/service/ebs/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/ebs/endpoints.go b/service/ebs/endpoints.go index 9fa930af503..dc18eb1e4d4 100644 --- a/service/ebs/endpoints.go +++ b/service/ebs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ebs/generated.json b/service/ebs/generated.json index 4409d7c3bc5..b02113b0c18 100644 --- a/service/ebs/generated.json +++ b/service/ebs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ebs/go.mod b/service/ebs/go.mod index 79549869be0..685c08968c3 100644 --- a/service/ebs/go.mod +++ b/service/ebs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ebs/internal/endpoints/endpoints.go b/service/ebs/internal/endpoints/endpoints.go index 927f2add75a..5c8c0282ec9 100644 --- a/service/ebs/internal/endpoints/endpoints.go +++ b/service/ebs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EBS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,113 +102,291 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ebs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ebs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ebs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ebs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "ebs-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ebs-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ebs-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ebs-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ebs-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ebs.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ebs.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ebs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ebs.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ebs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ebs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ebs.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ebs.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ebs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ebs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ebs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ebs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ebs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/ec2/api_client.go b/service/ec2/api_client.go index 6449c9b479d..da2bf6e0fb2 100644 --- a/service/ec2/api_client.go +++ b/service/ec2/api_client.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -135,6 +136,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -184,6 +187,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -212,7 +217,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -261,6 +266,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/ec2/endpoints.go b/service/ec2/endpoints.go index d26b615004d..47475fd5c1d 100644 --- a/service/ec2/endpoints.go +++ b/service/ec2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ec2/generated.json b/service/ec2/generated.json index 28941d7a210..67329c083a4 100644 --- a/service/ec2/generated.json +++ b/service/ec2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" diff --git a/service/ec2/go.mod b/service/ec2/go.mod index 50a736b41e8..b7d50d395cc 100644 --- a/service/ec2/go.mod +++ b/service/ec2/go.mod @@ -4,6 +4,8 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 @@ -11,4 +13,8 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/ec2/internal/endpoints/endpoints.go b/service/ec2/internal/endpoints/endpoints.go index 7aaf715d785..fda34fceb5d 100644 --- a/service/ec2/internal/endpoints/endpoints.go +++ b/service/ec2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EC2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,125 +102,345 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ec2.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.ap-south-1.aws", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.eu-west-1.aws", + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "ec2-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ec2-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ec2-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ec2-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ec2-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.sa-east-1.aws", + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.us-east-1.aws", + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.us-east-2.aws", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ec2.us-west-2.aws", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ec2.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ec2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ec2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ec2.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ec2.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ec2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ec2.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ec2.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/ec2instanceconnect/api_client.go b/service/ec2instanceconnect/api_client.go index a05c88ed873..61ef4c6e666 100644 --- a/service/ec2instanceconnect/api_client.go +++ b/service/ec2instanceconnect/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ec2instanceconnect/endpoints.go b/service/ec2instanceconnect/endpoints.go index 341df16fc5a..0ff03c06315 100644 --- a/service/ec2instanceconnect/endpoints.go +++ b/service/ec2instanceconnect/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ec2instanceconnect/generated.json b/service/ec2instanceconnect/generated.json index 79b1c473b07..587e7a3cbdb 100644 --- a/service/ec2instanceconnect/generated.json +++ b/service/ec2instanceconnect/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ec2instanceconnect/go.mod b/service/ec2instanceconnect/go.mod index a0927eb90d5..7f7425aacc3 100644 --- a/service/ec2instanceconnect/go.mod +++ b/service/ec2instanceconnect/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ec2instanceconnect/internal/endpoints/endpoints.go b/service/ec2instanceconnect/internal/endpoints/endpoints.go index 7f0f654966e..70142e71d75 100644 --- a/service/ec2instanceconnect/internal/endpoints/endpoints.go +++ b/service/ec2instanceconnect/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EC2 Instance Connect endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ec2-instance-connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2-instance-connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ec2-instance-connect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2-instance-connect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ec2-instance-connect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ec2-instance-connect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ec2-instance-connect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ec2-instance-connect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ec2-instance-connect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ec2-instance-connect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ec2-instance-connect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/ecr/api_client.go b/service/ecr/api_client.go index ff469b9a295..4e9acc0e683 100644 --- a/service/ecr/api_client.go +++ b/service/ecr/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ecr/endpoints.go b/service/ecr/endpoints.go index 6c3b7ef78b1..e255bc9d524 100644 --- a/service/ecr/endpoints.go +++ b/service/ecr/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ecr/generated.json b/service/ecr/generated.json index 7bd5a8ef189..a1aed452a66 100644 --- a/service/ecr/generated.json +++ b/service/ecr/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/ecr/go.mod b/service/ecr/go.mod index da28edaeb33..67518d943b2 100644 --- a/service/ecr/go.mod +++ b/service/ecr/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ecr/internal/endpoints/endpoints.go b/service/ecr/internal/endpoints/endpoints.go index 8077161db61..c6fbd0af95e 100644 --- a/service/ecr/internal/endpoints/endpoints.go +++ b/service/ecr/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ECR endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,207 +102,435 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.af-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "af-south-1", }, }, - "ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-east-1", }, }, - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, }, - "ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-northeast-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, }, - "ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "api.ecr.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dkr-us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-north-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, }, - "eu-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-south-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ Hostname: "api.ecr.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, }, - "fips-dkr-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-dkr-us-east-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-dkr-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-dkr-us-east-2", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-dkr-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-dkr-us-west-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-dkr-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-dkr-us-west-2", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.me-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "me-south-1", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, }, - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -265,21 +540,29 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.ecr.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", }, }, - "us-iso-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-iso-west-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-west-1", @@ -289,15 +572,21 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.ecr.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-isob-east-1.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", @@ -307,50 +596,145 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-dkr-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dkr-us-gov-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-gov-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "dkr-us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-dkr-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-dkr-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-dkr-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ecr-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "api.ecr.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecr-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, }, }, } diff --git a/service/ecrpublic/api_client.go b/service/ecrpublic/api_client.go index f3e42ef7def..e2e42620665 100644 --- a/service/ecrpublic/api_client.go +++ b/service/ecrpublic/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ecrpublic/endpoints.go b/service/ecrpublic/endpoints.go index 53564826349..071eca69cbb 100644 --- a/service/ecrpublic/endpoints.go +++ b/service/ecrpublic/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ecrpublic/generated.json b/service/ecrpublic/generated.json index b62a2747792..aa7e6d2e2f4 100644 --- a/service/ecrpublic/generated.json +++ b/service/ecrpublic/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ecrpublic/go.mod b/service/ecrpublic/go.mod index c03c1464c95..9e2372f70ef 100644 --- a/service/ecrpublic/go.mod +++ b/service/ecrpublic/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ecrpublic/internal/endpoints/endpoints.go b/service/ecrpublic/internal/endpoints/endpoints.go index 495e21fbb1e..07c4e84a720 100644 --- a/service/ecrpublic/internal/endpoints/endpoints.go +++ b/service/ecrpublic/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ECR PUBLIC endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,143 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr-public.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr-public.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ + Hostname: "api.ecr-public.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr-public.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr-public.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr-public.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.ecr-public.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr-public.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.ecr-public.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.ecr-public.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.ecr-public-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.ecr-public.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/ecs/api_client.go b/service/ecs/api_client.go index f73cd7fd545..aebe8109d41 100644 --- a/service/ecs/api_client.go +++ b/service/ecs/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ecs/endpoints.go b/service/ecs/endpoints.go index 649ee874ae7..a8a61bda37b 100644 --- a/service/ecs/endpoints.go +++ b/service/ecs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ecs/generated.json b/service/ecs/generated.json index e893edbcfb0..33a41c9bafc 100644 --- a/service/ecs/generated.json +++ b/service/ecs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/ecs/go.mod b/service/ecs/go.mod index 1d8eb86498b..4897327ad82 100644 --- a/service/ecs/go.mod +++ b/service/ecs/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ecs/internal/endpoints/endpoints.go b/service/ecs/internal/endpoints/endpoints.go index 850c5d8f294..2019f9716e8 100644 --- a/service/ecs/internal/endpoints/endpoints.go +++ b/service/ecs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ECS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ecs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ecs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ecs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ecs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ecs.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ecs.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ecs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ecs.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ecs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ecs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ecs.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ecs.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ecs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ecs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ecs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ecs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ecs-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ecs-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/efs/api_client.go b/service/efs/api_client.go index 2a4918e1617..1d9cf84d7c7 100644 --- a/service/efs/api_client.go +++ b/service/efs/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/efs/endpoints.go b/service/efs/endpoints.go index 29a1eb50719..ecac061b74e 100644 --- a/service/efs/endpoints.go +++ b/service/efs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/efs/generated.json b/service/efs/generated.json index ad802774bf9..16106d24121 100644 --- a/service/efs/generated.json +++ b/service/efs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/efs/go.mod b/service/efs/go.mod index cc77eb07d0e..ba39ede2cb7 100644 --- a/service/efs/go.mod +++ b/service/efs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/efs/internal/endpoints/endpoints.go b/service/efs/internal/endpoints/endpoints.go index c8dd855efad..7c67ce61f73 100644 --- a/service/efs/internal/endpoints/endpoints.go +++ b/service/efs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EFS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,242 +102,611 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticfilesystem.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticfilesystem.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-af-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.af-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-northeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-northeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-northeast-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-southeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ap-southeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-north-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.eu-west-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "fips-af-south-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.af-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "af-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-east-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-northeast-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-south-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-central-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-north-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-north-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-south-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-2", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-3", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, + Deprecated: aws.TrueTernary, }, - "fips-me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-me-south-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.me-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "me-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-sa-east-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.me-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.sa-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticfilesystem.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticfilesystem.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, - "fips-cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.cn-north-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.cn-northwest-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "fips-cn-north-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, + Deprecated: aws.TrueTernary, }, - "fips-cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticfilesystem.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticfilesystem.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-iso-east-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-iso-east-1.c2s.ic.gov", }, - "us-iso-east-1": endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticfilesystem.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticfilesystem.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticfilesystem.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticfilesystem-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticfilesystem.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "elasticfilesystem-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticfilesystem-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/eks/api_client.go b/service/eks/api_client.go index 1066a5c6590..50f3cd6b199 100644 --- a/service/eks/api_client.go +++ b/service/eks/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/eks/endpoints.go b/service/eks/endpoints.go index 5b5d879febc..b251f07c892 100644 --- a/service/eks/endpoints.go +++ b/service/eks/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/eks/generated.json b/service/eks/generated.json index eb9d4cae1d5..2e31eca969c 100644 --- a/service/eks/generated.json +++ b/service/eks/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/eks/go.mod b/service/eks/go.mod index 4916904e790..e27d7efd004 100644 --- a/service/eks/go.mod +++ b/service/eks/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/eks/internal/endpoints/endpoints.go b/service/eks/internal/endpoints/endpoints.go index 6ba0ee37d9f..fc43728e74b 100644 --- a/service/eks/internal/endpoints/endpoints.go +++ b/service/eks/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EKS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "eks.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "eks.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "eks-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "eks-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "eks.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "fips.eks.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "fips.eks.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "fips.eks.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "fips.eks.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.eks.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.eks.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.eks.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.eks.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "eks.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "eks.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "eks-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "eks-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "eks.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "eks.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "eks.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "eks.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "eks.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "eks.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "eks.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "eks-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "eks-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "eks.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "eks.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "eks.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "eks.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "eks.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/elasticache/api_client.go b/service/elasticache/api_client.go index b89f63dd0a0..d3f7c94d40e 100644 --- a/service/elasticache/api_client.go +++ b/service/elasticache/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticache/endpoints.go b/service/elasticache/endpoints.go index feebf2532be..501e2c85102 100644 --- a/service/elasticache/endpoints.go +++ b/service/elasticache/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticache/generated.json b/service/elasticache/generated.json index e7e6b1c6705..f1719228d58 100644 --- a/service/elasticache/generated.json +++ b/service/elasticache/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/elasticache/go.mod b/service/elasticache/go.mod index 0b877307a07..f63b9a4a3bf 100644 --- a/service/elasticache/go.mod +++ b/service/elasticache/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticache/internal/endpoints/endpoints.go b/service/elasticache/internal/endpoints/endpoints.go index 7beb322d704..4d49964c4a2 100644 --- a/service/elasticache/internal/endpoints/endpoints.go +++ b/service/elasticache/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ElastiCache endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,102 +102,245 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticache.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticache.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticache-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticache-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticache.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "elasticache-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticache.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticache.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticache-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticache-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticache.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticache.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticache.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticache.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticache.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticache.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticache.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticache-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticache-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticache.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "elasticache.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/elasticbeanstalk/api_client.go b/service/elasticbeanstalk/api_client.go index 870e845844f..90fc63d3ac4 100644 --- a/service/elasticbeanstalk/api_client.go +++ b/service/elasticbeanstalk/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticbeanstalk/endpoints.go b/service/elasticbeanstalk/endpoints.go index b36ef971e56..a994c6dc22e 100644 --- a/service/elasticbeanstalk/endpoints.go +++ b/service/elasticbeanstalk/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticbeanstalk/generated.json b/service/elasticbeanstalk/generated.json index 70a46a1a3fb..eeb8af8678d 100644 --- a/service/elasticbeanstalk/generated.json +++ b/service/elasticbeanstalk/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index a7c77b41e37..577697d16e7 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticbeanstalk/internal/endpoints/endpoints.go b/service/elasticbeanstalk/internal/endpoints/endpoints.go index 1cba36fc02b..1a93f7f12e0 100644 --- a/service/elasticbeanstalk/internal/endpoints/endpoints.go +++ b/service/elasticbeanstalk/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elastic Beanstalk endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,112 +102,281 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticbeanstalk.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticbeanstalk.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticbeanstalk.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticbeanstalk.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticbeanstalk.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticbeanstalk.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticbeanstalk.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticbeanstalk.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticbeanstalk.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticbeanstalk-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticbeanstalk.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "elasticbeanstalk.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/elasticinference/api_client.go b/service/elasticinference/api_client.go index 29bae7abc59..3b520da3272 100644 --- a/service/elasticinference/api_client.go +++ b/service/elasticinference/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticinference/endpoints.go b/service/elasticinference/endpoints.go index 2948f3dd560..03a095ab6e8 100644 --- a/service/elasticinference/endpoints.go +++ b/service/elasticinference/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticinference/generated.json b/service/elasticinference/generated.json index c65c605f092..cbe6dc08184 100644 --- a/service/elasticinference/generated.json +++ b/service/elasticinference/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/elasticinference/go.mod b/service/elasticinference/go.mod index 215e92bd6c7..eb25f115e1b 100644 --- a/service/elasticinference/go.mod +++ b/service/elasticinference/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticinference/internal/endpoints/endpoints.go b/service/elasticinference/internal/endpoints/endpoints.go index 7eb758057ed..c22ea057fb4 100644 --- a/service/elasticinference/internal/endpoints/endpoints.go +++ b/service/elasticinference/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elastic Inference endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,70 +102,165 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.elastic-inference.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.elastic-inference.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.ap-northeast-1.amazonaws.com", }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.ap-northeast-2.amazonaws.com", }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.eu-west-1.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.us-east-1.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.us-east-2.amazonaws.com", }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "api.elastic-inference.us-west-2.amazonaws.com", }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.elastic-inference.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.elastic-inference.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.elastic-inference.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.elastic-inference.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.elastic-inference.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.elastic-inference.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.elastic-inference.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.elastic-inference-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.elastic-inference.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/elasticloadbalancing/api_client.go b/service/elasticloadbalancing/api_client.go index cf00dea5234..920a2be97b4 100644 --- a/service/elasticloadbalancing/api_client.go +++ b/service/elasticloadbalancing/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticloadbalancing/endpoints.go b/service/elasticloadbalancing/endpoints.go index 5f892551ed7..0225514e769 100644 --- a/service/elasticloadbalancing/endpoints.go +++ b/service/elasticloadbalancing/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticloadbalancing/generated.json b/service/elasticloadbalancing/generated.json index b51aa0195a1..b260857a867 100644 --- a/service/elasticloadbalancing/generated.json +++ b/service/elasticloadbalancing/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/elasticloadbalancing/go.mod b/service/elasticloadbalancing/go.mod index 7a411944bc2..d0e305b21a8 100644 --- a/service/elasticloadbalancing/go.mod +++ b/service/elasticloadbalancing/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticloadbalancing/internal/endpoints/endpoints.go b/service/elasticloadbalancing/internal/endpoints/endpoints.go index 07d35f15c72..dc83e2c07c4 100644 --- a/service/elasticloadbalancing/internal/endpoints/endpoints.go +++ b/service/elasticloadbalancing/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elastic Load Balancing endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,130 +102,324 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + Protocols: []string{"http", "https"}, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, }, }, diff --git a/service/elasticloadbalancingv2/api_client.go b/service/elasticloadbalancingv2/api_client.go index 71cfdc5fe49..ae96c5d7d4e 100644 --- a/service/elasticloadbalancingv2/api_client.go +++ b/service/elasticloadbalancingv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticloadbalancingv2/endpoints.go b/service/elasticloadbalancingv2/endpoints.go index 96700286bd8..0abfae2801b 100644 --- a/service/elasticloadbalancingv2/endpoints.go +++ b/service/elasticloadbalancingv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticloadbalancingv2/generated.json b/service/elasticloadbalancingv2/generated.json index 2de5f06c666..ed8bc029fc0 100644 --- a/service/elasticloadbalancingv2/generated.json +++ b/service/elasticloadbalancingv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/elasticloadbalancingv2/go.mod b/service/elasticloadbalancingv2/go.mod index cb5e0093796..4658890b12a 100644 --- a/service/elasticloadbalancingv2/go.mod +++ b/service/elasticloadbalancingv2/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticloadbalancingv2/internal/endpoints/endpoints.go b/service/elasticloadbalancingv2/internal/endpoints/endpoints.go index da9a5b5c5b4..6d97f002d91 100644 --- a/service/elasticloadbalancingv2/internal/endpoints/endpoints.go +++ b/service/elasticloadbalancingv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elastic Load Balancing v2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,130 +102,324 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticloadbalancing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticloadbalancing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticloadbalancing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "elasticloadbalancing.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + Protocols: []string{"http", "https"}, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticloadbalancing.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, }, }, diff --git a/service/elasticsearchservice/api_client.go b/service/elasticsearchservice/api_client.go index 3e5ec79a917..93f8909c886 100644 --- a/service/elasticsearchservice/api_client.go +++ b/service/elasticsearchservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elasticsearchservice/endpoints.go b/service/elasticsearchservice/endpoints.go index b3aca46dd5c..6e5f2363c64 100644 --- a/service/elasticsearchservice/endpoints.go +++ b/service/elasticsearchservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elasticsearchservice/generated.json b/service/elasticsearchservice/generated.json index 3034bc0c95f..f1acd10eca7 100644 --- a/service/elasticsearchservice/generated.json +++ b/service/elasticsearchservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/elasticsearchservice/go.mod b/service/elasticsearchservice/go.mod index 1f9604b5245..64a6130cce9 100644 --- a/service/elasticsearchservice/go.mod +++ b/service/elasticsearchservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elasticsearchservice/internal/endpoints/endpoints.go b/service/elasticsearchservice/internal/endpoints/endpoints.go index 7899165ffd8..03df41844c4 100644 --- a/service/elasticsearchservice/internal/endpoints/endpoints.go +++ b/service/elasticsearchservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elasticsearch Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,101 +102,242 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "es-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "es.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "es.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "es-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/elastictranscoder/api_client.go b/service/elastictranscoder/api_client.go index b9b5ed5eb14..4e040a0513c 100644 --- a/service/elastictranscoder/api_client.go +++ b/service/elastictranscoder/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/elastictranscoder/endpoints.go b/service/elastictranscoder/endpoints.go index c4f74ab5f86..d7fad2e00bf 100644 --- a/service/elastictranscoder/endpoints.go +++ b/service/elastictranscoder/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/elastictranscoder/generated.json b/service/elastictranscoder/generated.json index b5215913e23..fc30ea05041 100644 --- a/service/elastictranscoder/generated.json +++ b/service/elastictranscoder/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/elastictranscoder/go.mod b/service/elastictranscoder/go.mod index ddea9a9787a..a87617dda1b 100644 --- a/service/elastictranscoder/go.mod +++ b/service/elastictranscoder/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/elastictranscoder/internal/endpoints/endpoints.go b/service/elastictranscoder/internal/endpoints/endpoints.go index f3f8500a3d8..f823631a518 100644 --- a/service/elastictranscoder/internal/endpoints/endpoints.go +++ b/service/elastictranscoder/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Elastic Transcoder endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,60 +102,159 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elastictranscoder.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elastictranscoder.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elastictranscoder.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elastictranscoder.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elastictranscoder.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elastictranscoder.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elastictranscoder.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elastictranscoder.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elastictranscoder.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elastictranscoder-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elastictranscoder.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/emr/api_client.go b/service/emr/api_client.go index f3e9800aeb2..9efb0734afe 100644 --- a/service/emr/api_client.go +++ b/service/emr/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/emr/endpoints.go b/service/emr/endpoints.go index 245109c6f46..282149cd2b4 100644 --- a/service/emr/endpoints.go +++ b/service/emr/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/emr/generated.json b/service/emr/generated.json index fde16ed3f51..a3f3a216cb0 100644 --- a/service/emr/generated.json +++ b/service/emr/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/emr/go.mod b/service/emr/go.mod index 60883d314e1..d8745e6de51 100644 --- a/service/emr/go.mod +++ b/service/emr/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/emr/internal/endpoints/endpoints.go b/service/emr/internal/endpoints/endpoints.go index bc9720336d4..e63102ebc0f 100644 --- a/service/emr/internal/endpoints/endpoints.go +++ b/service/emr/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EMR endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,134 +102,337 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "elasticmapreduce.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticmapreduce.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "elasticmapreduce.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticmapreduce.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "elasticmapreduce.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticmapreduce.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "elasticmapreduce.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "elasticmapreduce.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "elasticmapreduce.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "elasticmapreduce-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "elasticmapreduce.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "elasticmapreduce.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + Protocols: []string{"https"}, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "elasticmapreduce.us-gov-west-1.amazonaws.com", Protocols: []string{"https"}, }, }, diff --git a/service/emrcontainers/api_client.go b/service/emrcontainers/api_client.go index 0f156080f59..9d3cfcfe70d 100644 --- a/service/emrcontainers/api_client.go +++ b/service/emrcontainers/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/emrcontainers/endpoints.go b/service/emrcontainers/endpoints.go index 0d988bb423c..6f5123af63e 100644 --- a/service/emrcontainers/endpoints.go +++ b/service/emrcontainers/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/emrcontainers/generated.json b/service/emrcontainers/generated.json index 715e8ab45ae..012158122ad 100644 --- a/service/emrcontainers/generated.json +++ b/service/emrcontainers/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/emrcontainers/go.mod b/service/emrcontainers/go.mod index d171f02648c..27664cf9088 100644 --- a/service/emrcontainers/go.mod +++ b/service/emrcontainers/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/emrcontainers/internal/endpoints/endpoints.go b/service/emrcontainers/internal/endpoints/endpoints.go index 71bbd73cef4..687d4a2c198 100644 --- a/service/emrcontainers/internal/endpoints/endpoints.go +++ b/service/emrcontainers/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EMR containers endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,102 +102,266 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "emr-containers.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "emr-containers.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "emr-containers-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "emr-containers.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "emr-containers-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "emr-containers-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "emr-containers-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "emr-containers-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "emr-containers-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "emr-containers.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "emr-containers.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "emr-containers-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "emr-containers.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "emr-containers.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "emr-containers.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "emr-containers.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "emr-containers.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "emr-containers.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "emr-containers.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "emr-containers-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "emr-containers-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "emr-containers.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/eventbridge/api_client.go b/service/eventbridge/api_client.go index 917d57f6333..914ea55567a 100644 --- a/service/eventbridge/api_client.go +++ b/service/eventbridge/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/eventbridge/endpoints.go b/service/eventbridge/endpoints.go index fd44a02e4e3..5c44bb4963a 100644 --- a/service/eventbridge/endpoints.go +++ b/service/eventbridge/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/eventbridge/generated.json b/service/eventbridge/generated.json index dde8d327c48..297d87a1fc6 100644 --- a/service/eventbridge/generated.json +++ b/service/eventbridge/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/eventbridge/go.mod b/service/eventbridge/go.mod index 9f8ae7b946d..7d8c1a7d389 100644 --- a/service/eventbridge/go.mod +++ b/service/eventbridge/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/eventbridge/internal/endpoints/endpoints.go b/service/eventbridge/internal/endpoints/endpoints.go index 15848abfb32..5dea010ff2f 100644 --- a/service/eventbridge/internal/endpoints/endpoints.go +++ b/service/eventbridge/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver EventBridge endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "events-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "events-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "events-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "events-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "events.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "events.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "events.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "events.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/finspace/api_client.go b/service/finspace/api_client.go index 0a1bb0a6b7e..cc6c6f43a7f 100644 --- a/service/finspace/api_client.go +++ b/service/finspace/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -127,6 +128,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -176,6 +179,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -204,7 +209,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -246,6 +251,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + type customizeRestJsonContentType struct { } diff --git a/service/finspace/endpoints.go b/service/finspace/endpoints.go index fdba9b27cbb..c2f7e198b87 100644 --- a/service/finspace/endpoints.go +++ b/service/finspace/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/finspace/generated.json b/service/finspace/generated.json index 2fd8f1b0ce3..b6a087d17f5 100644 --- a/service/finspace/generated.json +++ b/service/finspace/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/finspace/go.mod b/service/finspace/go.mod index b45bcbe4ebe..cbf6c3a1975 100644 --- a/service/finspace/go.mod +++ b/service/finspace/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/finspace/internal/endpoints/endpoints.go b/service/finspace/internal/endpoints/endpoints.go index e1d6664c301..b8c322e5ac9 100644 --- a/service/finspace/internal/endpoints/endpoints.go +++ b/service/finspace/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver finspace endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,57 +102,150 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "finspace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ca-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "finspace.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "finspace.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "finspace.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "finspace.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "finspace.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "finspace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/finspacedata/api_client.go b/service/finspacedata/api_client.go index 70b04b2d4cb..e8b17a7daf6 100644 --- a/service/finspacedata/api_client.go +++ b/service/finspacedata/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -126,6 +127,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -175,6 +178,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -203,7 +208,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -245,6 +250,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + type customizeRestJsonContentType struct { } diff --git a/service/finspacedata/endpoints.go b/service/finspacedata/endpoints.go index 713b3b5324f..852442b947f 100644 --- a/service/finspacedata/endpoints.go +++ b/service/finspacedata/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/finspacedata/generated.json b/service/finspacedata/generated.json index 8633315d9b5..0efab1eba04 100644 --- a/service/finspacedata/generated.json +++ b/service/finspacedata/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/finspacedata/go.mod b/service/finspacedata/go.mod index 44a4ff88528..da6cc5159b9 100644 --- a/service/finspacedata/go.mod +++ b/service/finspacedata/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/finspacedata/internal/endpoints/endpoints.go b/service/finspacedata/internal/endpoints/endpoints.go index 4ef7e91e42a..0fad456391e 100644 --- a/service/finspacedata/internal/endpoints/endpoints.go +++ b/service/finspacedata/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver finspace data endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,57 +102,150 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "finspace-api.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace-api.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-api-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-api-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace-api.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ca-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "finspace-api.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace-api.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-api-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-api-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace-api.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "finspace-api.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "finspace-api.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "finspace-api.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "finspace-api.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "finspace-api.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "finspace-api.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "finspace-api-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "finspace-api-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "finspace-api.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/firehose/api_client.go b/service/firehose/api_client.go index 1f0c8d0a54c..89ade1c6d93 100644 --- a/service/firehose/api_client.go +++ b/service/firehose/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/firehose/endpoints.go b/service/firehose/endpoints.go index 392d0106733..1f68ebc6ec7 100644 --- a/service/firehose/endpoints.go +++ b/service/firehose/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/firehose/generated.json b/service/firehose/generated.json index c76257f824a..53d505d1bd1 100644 --- a/service/firehose/generated.json +++ b/service/firehose/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/firehose/go.mod b/service/firehose/go.mod index 25cafd88270..ccc4e5c56c3 100644 --- a/service/firehose/go.mod +++ b/service/firehose/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/firehose/internal/endpoints/endpoints.go b/service/firehose/internal/endpoints/endpoints.go index 47593621856..2473264a478 100644 --- a/service/firehose/internal/endpoints/endpoints.go +++ b/service/firehose/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Firehose endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,122 +102,311 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "firehose.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "firehose.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "firehose-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "firehose.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "firehose.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "firehose.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "firehose-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "firehose.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "firehose.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "firehose.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "firehose.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "firehose.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "firehose.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "firehose.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "firehose-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "firehose.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "firehose-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "firehose-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/fis/api_client.go b/service/fis/api_client.go index 42ecb8d9d34..4d49075dbbe 100644 --- a/service/fis/api_client.go +++ b/service/fis/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/fis/endpoints.go b/service/fis/endpoints.go index 422cfa1d676..3e97b35eb08 100644 --- a/service/fis/endpoints.go +++ b/service/fis/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/fis/generated.json b/service/fis/generated.json index 2259f9fcda3..b3a8149b8ee 100644 --- a/service/fis/generated.json +++ b/service/fis/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/fis/go.mod b/service/fis/go.mod index c45b7c70823..655468b45b9 100644 --- a/service/fis/go.mod +++ b/service/fis/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/fis/internal/endpoints/endpoints.go b/service/fis/internal/endpoints/endpoints.go index 65127706ea1..f7c98c56b97 100644 --- a/service/fis/internal/endpoints/endpoints.go +++ b/service/fis/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver fis endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "fis.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fis.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fis-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fis-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fis.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "fis.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fis.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fis-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fis-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fis.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "fis.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fis.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "fis.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fis.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "fis.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fis.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fis-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fis-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fis.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/fms/api_client.go b/service/fms/api_client.go index 76ca620956b..0cbac2e4d4a 100644 --- a/service/fms/api_client.go +++ b/service/fms/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/fms/endpoints.go b/service/fms/endpoints.go index a92eee8f7bc..7e490492e1c 100644 --- a/service/fms/endpoints.go +++ b/service/fms/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/fms/generated.json b/service/fms/generated.json index a0879eed409..cc3626ad03b 100644 --- a/service/fms/generated.json +++ b/service/fms/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/fms/go.mod b/service/fms/go.mod index 7e98038da0d..ba1a3b6aa42 100644 --- a/service/fms/go.mod +++ b/service/fms/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/fms/internal/endpoints/endpoints.go b/service/fms/internal/endpoints/endpoints.go index 28c06195a24..8ae8189296f 100644 --- a/service/fms/internal/endpoints/endpoints.go +++ b/service/fms/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver FMS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,209 +102,531 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "fms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-af-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.af-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-northeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-northeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-southeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ap-southeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.eu-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.eu-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.eu-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.eu-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.eu-west-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "fips-af-south-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.af-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "af-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-east-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-south-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "fms-fips.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-central-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-south-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.eu-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-2", + }: endpoints.Endpoint{ Hostname: "fms-fips.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-3", + }: endpoints.Endpoint{ Hostname: "fms-fips.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, + Deprecated: aws.TrueTernary, }, - "fips-me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-me-south-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.me-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "me-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-sa-east-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.me-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.sa-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "fms.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fms.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fms-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fms.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "fms.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fms.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "fms.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fms.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "fms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "fms-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fms-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/forecast/api_client.go b/service/forecast/api_client.go index 14d97243f8c..e47429ff878 100644 --- a/service/forecast/api_client.go +++ b/service/forecast/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/forecast/endpoints.go b/service/forecast/endpoints.go index a3a920a0403..8c9a73cdad9 100644 --- a/service/forecast/endpoints.go +++ b/service/forecast/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/forecast/generated.json b/service/forecast/generated.json index 1bd8c9ad6ac..d6430c38118 100644 --- a/service/forecast/generated.json +++ b/service/forecast/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/forecast/go.mod b/service/forecast/go.mod index 36d53db5c63..a81237f090e 100644 --- a/service/forecast/go.mod +++ b/service/forecast/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/forecast/internal/endpoints/endpoints.go b/service/forecast/internal/endpoints/endpoints.go index 00a25131d76..b258cc890f6 100644 --- a/service/forecast/internal/endpoints/endpoints.go +++ b/service/forecast/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver forecast endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "forecast.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "forecast.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/forecastquery/api_client.go b/service/forecastquery/api_client.go index b59d5d1719b..532c9e0bb87 100644 --- a/service/forecastquery/api_client.go +++ b/service/forecastquery/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/forecastquery/endpoints.go b/service/forecastquery/endpoints.go index 90a375a3d97..a4a1d2a9d7c 100644 --- a/service/forecastquery/endpoints.go +++ b/service/forecastquery/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/forecastquery/generated.json b/service/forecastquery/generated.json index 850fe6b541f..6f7cd440787 100644 --- a/service/forecastquery/generated.json +++ b/service/forecastquery/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/forecastquery/go.mod b/service/forecastquery/go.mod index 5b4ae12ce31..c6bf5ff5b41 100644 --- a/service/forecastquery/go.mod +++ b/service/forecastquery/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/forecastquery/internal/endpoints/endpoints.go b/service/forecastquery/internal/endpoints/endpoints.go index 704497ec88e..3448354c5a2 100644 --- a/service/forecastquery/internal/endpoints/endpoints.go +++ b/service/forecastquery/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver forecastquery endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "forecast-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "forecast.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "forecast.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "forecast.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "forecast.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "forecast-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "forecast-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "forecast.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/frauddetector/api_client.go b/service/frauddetector/api_client.go index 1fe2cfd2154..00f80938109 100644 --- a/service/frauddetector/api_client.go +++ b/service/frauddetector/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/frauddetector/endpoints.go b/service/frauddetector/endpoints.go index d4c6d4b9a4f..0b0d6f2f741 100644 --- a/service/frauddetector/endpoints.go +++ b/service/frauddetector/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/frauddetector/generated.json b/service/frauddetector/generated.json index 841bef24df5..7640653faef 100644 --- a/service/frauddetector/generated.json +++ b/service/frauddetector/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/frauddetector/go.mod b/service/frauddetector/go.mod index 24a3a2681f8..abd3cf42d3b 100644 --- a/service/frauddetector/go.mod +++ b/service/frauddetector/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/frauddetector/internal/endpoints/endpoints.go b/service/frauddetector/internal/endpoints/endpoints.go index 15064bd22f7..6cc719cb62f 100644 --- a/service/frauddetector/internal/endpoints/endpoints.go +++ b/service/frauddetector/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver FraudDetector endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,58 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "frauddetector.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "frauddetector.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "frauddetector-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "frauddetector-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "frauddetector.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "frauddetector.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "frauddetector.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "frauddetector-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "frauddetector-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "frauddetector.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "frauddetector.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "frauddetector.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "frauddetector.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "frauddetector.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "frauddetector.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "frauddetector.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "frauddetector-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "frauddetector-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "frauddetector.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/fsx/api_client.go b/service/fsx/api_client.go index d8e117aeccc..669761ad4bf 100644 --- a/service/fsx/api_client.go +++ b/service/fsx/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/fsx/endpoints.go b/service/fsx/endpoints.go index 4d833d2e67e..4811178b36d 100644 --- a/service/fsx/endpoints.go +++ b/service/fsx/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/fsx/generated.json b/service/fsx/generated.json index c4c88f8de74..f3d704622b0 100644 --- a/service/fsx/generated.json +++ b/service/fsx/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/fsx/go.mod b/service/fsx/go.mod index afbe76bbe10..e29313e19ce 100644 --- a/service/fsx/go.mod +++ b/service/fsx/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/fsx/internal/endpoints/endpoints.go b/service/fsx/internal/endpoints/endpoints.go index de2bd7f9f76..93c03e46386 100644 --- a/service/fsx/internal/endpoints/endpoints.go +++ b/service/fsx/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver FSx endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,125 +102,405 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "fsx.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fsx.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fsx-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fsx-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fsx.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-prod-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-prod-ca-central-1", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-prod-us-east-1", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-prod-us-east-2", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-prod-us-west-1", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-prod-us-west-2", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "prod-ca-central-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-ca-central-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-prod-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "prod-us-east-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "fips-prod-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "prod-us-east-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-prod-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "prod-us-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, }, - "fips-prod-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "prod-us-west-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "fsx.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fsx.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fsx-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fsx-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fsx.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "fsx.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fsx.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "fsx.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "fsx.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "fsx.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "fsx.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fsx-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "fsx-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "fsx.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-prod-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-prod-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "fsx-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "fips-prod-us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "fsx-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-gov-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fsx-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "prod-us-gov-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-prod-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "prod-us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "fsx-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/gamelift/api_client.go b/service/gamelift/api_client.go index aac60dfb478..c5967f55ec1 100644 --- a/service/gamelift/api_client.go +++ b/service/gamelift/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/gamelift/endpoints.go b/service/gamelift/endpoints.go index 65ac8cca0c6..fb33f362967 100644 --- a/service/gamelift/endpoints.go +++ b/service/gamelift/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/gamelift/generated.json b/service/gamelift/generated.json index 442b5faa537..fe152ffcd8d 100644 --- a/service/gamelift/generated.json +++ b/service/gamelift/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/gamelift/go.mod b/service/gamelift/go.mod index f0f41b3fd55..612f0d3fecb 100644 --- a/service/gamelift/go.mod +++ b/service/gamelift/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/gamelift/internal/endpoints/endpoints.go b/service/gamelift/internal/endpoints/endpoints.go index 44db1b296b2..cc00470255e 100644 --- a/service/gamelift/internal/endpoints/endpoints.go +++ b/service/gamelift/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver GameLift endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,76 +102,203 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "gamelift.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "gamelift.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "gamelift-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "gamelift-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "gamelift.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "gamelift.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "gamelift.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "gamelift-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "gamelift-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "gamelift.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "gamelift.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "gamelift.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "gamelift.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "gamelift.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "gamelift.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "gamelift.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "gamelift-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "gamelift-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "gamelift.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/glacier/api_client.go b/service/glacier/api_client.go index 8a6eadbcf0d..2a6371fb97a 100644 --- a/service/glacier/api_client.go +++ b/service/glacier/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/glacier/endpoints.go b/service/glacier/endpoints.go index 11ac8ef9dbf..31d44ad6abf 100644 --- a/service/glacier/endpoints.go +++ b/service/glacier/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/glacier/generated.json b/service/glacier/generated.json index cf5b32b159a..b32a8b10e41 100644 --- a/service/glacier/generated.json +++ b/service/glacier/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/glacier/go.mod b/service/glacier/go.mod index 185e7c99880..6db6cbe1095 100644 --- a/service/glacier/go.mod +++ b/service/glacier/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/glacier/internal/endpoints/endpoints.go b/service/glacier/internal/endpoints/endpoints.go index b025291235e..a545cfaaf05 100644 --- a/service/glacier/internal/endpoints/endpoints.go +++ b/service/glacier/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Glacier endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,127 +102,311 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "glacier.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glacier.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glacier-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glacier.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "glacier-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "glacier-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "glacier-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "glacier-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "glacier-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "glacier.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glacier.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glacier-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glacier.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "glacier.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "glacier.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "glacier.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "glacier.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "glacier.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glacier.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glacier-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glacier-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glacier.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "glacier.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "glacier.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, CredentialScope: endpoints.CredentialScope{ diff --git a/service/globalaccelerator/api_client.go b/service/globalaccelerator/api_client.go index 8152655f1f3..4ddf515bfd7 100644 --- a/service/globalaccelerator/api_client.go +++ b/service/globalaccelerator/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/globalaccelerator/endpoints.go b/service/globalaccelerator/endpoints.go index 5939ce1b6f2..cdf96510e3b 100644 --- a/service/globalaccelerator/endpoints.go +++ b/service/globalaccelerator/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/globalaccelerator/generated.json b/service/globalaccelerator/generated.json index cf3353f06f0..51f84005dba 100644 --- a/service/globalaccelerator/generated.json +++ b/service/globalaccelerator/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/globalaccelerator/go.mod b/service/globalaccelerator/go.mod index c017a55c29d..629a71e4f9a 100644 --- a/service/globalaccelerator/go.mod +++ b/service/globalaccelerator/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/globalaccelerator/internal/endpoints/endpoints.go b/service/globalaccelerator/internal/endpoints/endpoints.go index af477d74ca9..2dea8326204 100644 --- a/service/globalaccelerator/internal/endpoints/endpoints.go +++ b/service/globalaccelerator/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Global Accelerator endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "globalaccelerator.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "globalaccelerator.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "globalaccelerator.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "globalaccelerator.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "globalaccelerator.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "globalaccelerator.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "globalaccelerator.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "globalaccelerator.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "globalaccelerator.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "globalaccelerator-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "globalaccelerator.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/glue/api_client.go b/service/glue/api_client.go index bae3cde9e6c..293210b3b7d 100644 --- a/service/glue/api_client.go +++ b/service/glue/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/glue/endpoints.go b/service/glue/endpoints.go index 831c4641a37..f98f786eed2 100644 --- a/service/glue/endpoints.go +++ b/service/glue/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/glue/generated.json b/service/glue/generated.json index 3031d2efef5..dd020d631c8 100644 --- a/service/glue/generated.json +++ b/service/glue/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/glue/go.mod b/service/glue/go.mod index 82845753726..f804c7a653b 100644 --- a/service/glue/go.mod +++ b/service/glue/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/glue/internal/endpoints/endpoints.go b/service/glue/internal/endpoints/endpoints.go index 8087602acbf..e8db21ca817 100644 --- a/service/glue/internal/endpoints/endpoints.go +++ b/service/glue/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Glue endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "glue.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glue.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glue-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glue.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "glue.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glue.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glue-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glue.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "glue.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "glue.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "glue.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "glue.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "glue.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "glue.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "glue-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "glue.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "glue-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "glue-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/grafana/api_client.go b/service/grafana/api_client.go index 2e017df2ba0..e7f344e3678 100644 --- a/service/grafana/api_client.go +++ b/service/grafana/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/grafana/endpoints.go b/service/grafana/endpoints.go index 0951362f338..94629e739bc 100644 --- a/service/grafana/endpoints.go +++ b/service/grafana/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/grafana/generated.json b/service/grafana/generated.json index 3f939ee0cf7..a61570b04dc 100644 --- a/service/grafana/generated.json +++ b/service/grafana/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/grafana/go.mod b/service/grafana/go.mod index bb0513d7814..8164192e724 100644 --- a/service/grafana/go.mod +++ b/service/grafana/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/grafana/internal/endpoints/endpoints.go b/service/grafana/internal/endpoints/endpoints.go index 7b8c5e4d1ea..1c6442e10c3 100644 --- a/service/grafana/internal/endpoints/endpoints.go +++ b/service/grafana/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver grafana endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,114 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "grafana.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "grafana.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "grafana-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "grafana-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "grafana.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "grafana.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "grafana.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "grafana.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "grafana.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "grafana.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "grafana.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "grafana.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "grafana.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "grafana.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "grafana.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", @@ -127,40 +219,98 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "grafana.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "grafana.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "grafana-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "grafana-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "grafana.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "grafana.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "grafana.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "grafana.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "grafana.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "grafana.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "grafana.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "grafana-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "grafana-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "grafana.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/greengrass/api_client.go b/service/greengrass/api_client.go index 137ca152cf1..6a83c57cc59 100644 --- a/service/greengrass/api_client.go +++ b/service/greengrass/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/greengrass/endpoints.go b/service/greengrass/endpoints.go index 7dbc4929044..fa539ae43f9 100644 --- a/service/greengrass/endpoints.go +++ b/service/greengrass/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/greengrass/generated.json b/service/greengrass/generated.json index da06b23ef0d..3ae42f1d6df 100644 --- a/service/greengrass/generated.json +++ b/service/greengrass/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/greengrass/go.mod b/service/greengrass/go.mod index 121184e4cd9..dcd4b40e77d 100644 --- a/service/greengrass/go.mod +++ b/service/greengrass/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/greengrass/internal/endpoints/endpoints.go b/service/greengrass/internal/endpoints/endpoints.go index e8f20ad2f75..736a1858ef6 100644 --- a/service/greengrass/internal/endpoints/endpoints.go +++ b/service/greengrass/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Greengrass endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,95 +102,222 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "dataplane-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dataplane-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass-ats.iot.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "dataplane-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dataplane-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "greengrass-ats.iot.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "greengrass.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/greengrassv2/api_client.go b/service/greengrassv2/api_client.go index eb80d3048ff..f3b63ce211a 100644 --- a/service/greengrassv2/api_client.go +++ b/service/greengrassv2/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/greengrassv2/endpoints.go b/service/greengrassv2/endpoints.go index 97daaa2124c..057e04d4081 100644 --- a/service/greengrassv2/endpoints.go +++ b/service/greengrassv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/greengrassv2/generated.json b/service/greengrassv2/generated.json index d250d644cb0..361b3401499 100644 --- a/service/greengrassv2/generated.json +++ b/service/greengrassv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/greengrassv2/go.mod b/service/greengrassv2/go.mod index e98392aee43..1b497e0e147 100644 --- a/service/greengrassv2/go.mod +++ b/service/greengrassv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/greengrassv2/internal/endpoints/endpoints.go b/service/greengrassv2/internal/endpoints/endpoints.go index 15b34cb3e73..79fcd290df2 100644 --- a/service/greengrassv2/internal/endpoints/endpoints.go +++ b/service/greengrassv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver GreengrassV2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,95 +102,222 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "greengrass.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "greengrass.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "greengrass-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "greengrass.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "dataplane-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dataplane-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass-ats.iot.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "dataplane-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "dataplane-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "greengrass-ats.iot.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "greengrass.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "greengrass-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "greengrass.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/groundstation/api_client.go b/service/groundstation/api_client.go index b38e6d61eef..0b582c110bc 100644 --- a/service/groundstation/api_client.go +++ b/service/groundstation/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/groundstation/endpoints.go b/service/groundstation/endpoints.go index b4814f68fae..b58756b5903 100644 --- a/service/groundstation/endpoints.go +++ b/service/groundstation/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/groundstation/generated.json b/service/groundstation/generated.json index 9d7a6da591e..2d3eb5a32b1 100644 --- a/service/groundstation/generated.json +++ b/service/groundstation/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/groundstation/go.mod b/service/groundstation/go.mod index a17d1b65e69..0b2c6b3b76c 100644 --- a/service/groundstation/go.mod +++ b/service/groundstation/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/groundstation/internal/endpoints/endpoints.go b/service/groundstation/internal/endpoints/endpoints.go index 6edb5f06f1e..d808ccd0c67 100644 --- a/service/groundstation/internal/endpoints/endpoints.go +++ b/service/groundstation/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver GroundStation endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "groundstation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "groundstation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "groundstation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "groundstation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "groundstation-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "groundstation-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "groundstation-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "groundstation.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "groundstation.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "groundstation-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "groundstation.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "groundstation.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "groundstation.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "groundstation.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "groundstation.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "groundstation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "groundstation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "groundstation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "groundstation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "groundstation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/guardduty/api_client.go b/service/guardduty/api_client.go index 9bd023425c9..a2a0629ecbe 100644 --- a/service/guardduty/api_client.go +++ b/service/guardduty/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/guardduty/endpoints.go b/service/guardduty/endpoints.go index 68b9de78a12..88c79069c18 100644 --- a/service/guardduty/endpoints.go +++ b/service/guardduty/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/guardduty/generated.json b/service/guardduty/generated.json index ed34ee9e746..86933906881 100644 --- a/service/guardduty/generated.json +++ b/service/guardduty/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/guardduty/go.mod b/service/guardduty/go.mod index ffcabf1bb25..d4680629f33 100644 --- a/service/guardduty/go.mod +++ b/service/guardduty/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/guardduty/internal/endpoints/endpoints.go b/service/guardduty/internal/endpoints/endpoints.go index cb108737298..cc327b5ebed 100644 --- a/service/guardduty/internal/endpoints/endpoints.go +++ b/service/guardduty/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver GuardDuty endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,305 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "guardduty.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "guardduty.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "guardduty-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "guardduty.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "guardduty-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "guardduty-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "guardduty-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "guardduty-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "guardduty.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "guardduty.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "guardduty-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "guardduty.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "guardduty.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "guardduty.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "guardduty.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "guardduty.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "guardduty.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "guardduty.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "guardduty-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "guardduty.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "guardduty.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "guardduty.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "guardduty.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/health/api_client.go b/service/health/api_client.go index ab241a11014..dfd6a0b8cac 100644 --- a/service/health/api_client.go +++ b/service/health/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/health/endpoints.go b/service/health/endpoints.go index ea562902b95..708efd82633 100644 --- a/service/health/endpoints.go +++ b/service/health/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/health/generated.json b/service/health/generated.json index bef4b99d5a3..b3856bfa0e9 100644 --- a/service/health/generated.json +++ b/service/health/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/health/go.mod b/service/health/go.mod index ec0e10fee06..9fae44c131a 100644 --- a/service/health/go.mod +++ b/service/health/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/health/internal/endpoints/endpoints.go b/service/health/internal/endpoints/endpoints.go index 7a6f880a2b9..452b1977567 100644 --- a/service/health/internal/endpoints/endpoints.go +++ b/service/health/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Health endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,77 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "health.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "health.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "health-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "health-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "health.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "health-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "health-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "health.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "health.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "health-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "health-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "health.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "health.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "health.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "health.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "health.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "health.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "health.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "health-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "health-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "health.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "health-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "health-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/healthlake/api_client.go b/service/healthlake/api_client.go index 1287ce85606..3c82d5200a2 100644 --- a/service/healthlake/api_client.go +++ b/service/healthlake/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/healthlake/endpoints.go b/service/healthlake/endpoints.go index 21f8959fd6a..40fb70851fc 100644 --- a/service/healthlake/endpoints.go +++ b/service/healthlake/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/healthlake/generated.json b/service/healthlake/generated.json index 7cff825c881..c23eb5c664d 100644 --- a/service/healthlake/generated.json +++ b/service/healthlake/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/healthlake/go.mod b/service/healthlake/go.mod index bcc93d18d1f..68169519be6 100644 --- a/service/healthlake/go.mod +++ b/service/healthlake/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/healthlake/internal/endpoints/endpoints.go b/service/healthlake/internal/endpoints/endpoints.go index 52dbcb03eb9..6af889671a4 100644 --- a/service/healthlake/internal/endpoints/endpoints.go +++ b/service/healthlake/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver HealthLake endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,55 +102,144 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "healthlake.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "healthlake.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "healthlake-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "healthlake-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "healthlake.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "healthlake.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "healthlake.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "healthlake-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "healthlake-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "healthlake.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "healthlake.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "healthlake.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "healthlake.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "healthlake.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "healthlake.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "healthlake.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "healthlake-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "healthlake-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "healthlake.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/honeycode/api_client.go b/service/honeycode/api_client.go index 04fc93fe765..64f7b75e61a 100644 --- a/service/honeycode/api_client.go +++ b/service/honeycode/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/honeycode/endpoints.go b/service/honeycode/endpoints.go index 5112ecb07dd..477f75432e5 100644 --- a/service/honeycode/endpoints.go +++ b/service/honeycode/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/honeycode/generated.json b/service/honeycode/generated.json index 90ac648d0c5..033ddd02c78 100644 --- a/service/honeycode/generated.json +++ b/service/honeycode/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/honeycode/go.mod b/service/honeycode/go.mod index a498d59c502..d5e2bd0af41 100644 --- a/service/honeycode/go.mod +++ b/service/honeycode/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/honeycode/internal/endpoints/endpoints.go b/service/honeycode/internal/endpoints/endpoints.go index 3301bdd0ea0..91ac17b98c5 100644 --- a/service/honeycode/internal/endpoints/endpoints.go +++ b/service/honeycode/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Honeycode endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,53 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "honeycode.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "honeycode.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "honeycode-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "honeycode-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "honeycode.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "honeycode.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "honeycode.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "honeycode-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "honeycode-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "honeycode.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "honeycode.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "honeycode.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "honeycode.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "honeycode.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "honeycode.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "honeycode.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "honeycode-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "honeycode-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "honeycode.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iam/api_client.go b/service/iam/api_client.go index 15794191a59..691f8e58086 100644 --- a/service/iam/api_client.go +++ b/service/iam/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iam/endpoints.go b/service/iam/endpoints.go index a453cbe76ca..f69c024737e 100644 --- a/service/iam/endpoints.go +++ b/service/iam/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iam/generated.json b/service/iam/generated.json index b982aa97fe6..382664900ad 100644 --- a/service/iam/generated.json +++ b/service/iam/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iam/go.mod b/service/iam/go.mod index 981e32cd870..6a000a54c52 100644 --- a/service/iam/go.mod +++ b/service/iam/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iam/internal/endpoints/endpoints.go b/service/iam/internal/endpoints/endpoints.go index feacfef9e17..84618017e64 100644 --- a/service/iam/internal/endpoints/endpoints.go +++ b/service/iam/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IAM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,41 +102,116 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iam.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iam.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iam-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iam-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iam.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "iam.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "iam-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "iam", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "iam", + Variant: endpoints.FIPSVariant, + }: { Hostname: "iam-fips.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "iam-fips", + }: endpoints.Endpoint{ + Hostname: "iam-fips.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iam.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iam.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iam-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iam-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iam.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "iam.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", @@ -99,16 +221,22 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iam.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iam.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: false, PartitionEndpoint: "aws-iso-global", Endpoints: endpoints.Endpoints{ - "aws-iso-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-global", + }: endpoints.Endpoint{ Hostname: "iam.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", @@ -118,16 +246,22 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iam.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iam.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: false, PartitionEndpoint: "aws-iso-b-global", Endpoints: endpoints.Endpoints{ - "aws-iso-b-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-b-global", + }: endpoints.Endpoint{ Hostname: "iam.us-isob-east-1.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", @@ -137,26 +271,74 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iam.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iam.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iam-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iam-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iam.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: false, PartitionEndpoint: "aws-us-gov-global", Endpoints: endpoints.Endpoints{ - "aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + }: endpoints.Endpoint{ + Hostname: "iam.us-gov.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "iam-govcloud", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "iam-govcloud", + Variant: endpoints.FIPSVariant, + }: { Hostname: "iam.us-gov.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "iam-govcloud-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "iam-govcloud-fips", + }: endpoints.Endpoint{ Hostname: "iam.us-gov.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/identitystore/api_client.go b/service/identitystore/api_client.go index 6bd59cd3e7f..6b12df5691a 100644 --- a/service/identitystore/api_client.go +++ b/service/identitystore/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/identitystore/endpoints.go b/service/identitystore/endpoints.go index c65fa920fd3..d6f5c6e56f4 100644 --- a/service/identitystore/endpoints.go +++ b/service/identitystore/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/identitystore/generated.json b/service/identitystore/generated.json index 3252efa1895..bed3077e1c2 100644 --- a/service/identitystore/generated.json +++ b/service/identitystore/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/identitystore/go.mod b/service/identitystore/go.mod index 54661448cdd..f35b5101316 100644 --- a/service/identitystore/go.mod +++ b/service/identitystore/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/identitystore/internal/endpoints/endpoints.go b/service/identitystore/internal/endpoints/endpoints.go index 1d021031d4f..8892139061f 100644 --- a/service/identitystore/internal/endpoints/endpoints.go +++ b/service/identitystore/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver identitystore endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,76 +102,196 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "identitystore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identitystore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identitystore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identitystore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identitystore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "identitystore.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identitystore.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identitystore-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identitystore-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identitystore.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "identitystore.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "identitystore.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "identitystore.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "identitystore.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "identitystore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "identitystore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identitystore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "identitystore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "identitystore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "identitystore.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "identitystore.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/imagebuilder/api_client.go b/service/imagebuilder/api_client.go index 9ee8afdd09e..eea4e1f340d 100644 --- a/service/imagebuilder/api_client.go +++ b/service/imagebuilder/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/imagebuilder/endpoints.go b/service/imagebuilder/endpoints.go index 1223a18a221..bd47a1917c7 100644 --- a/service/imagebuilder/endpoints.go +++ b/service/imagebuilder/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/imagebuilder/generated.json b/service/imagebuilder/generated.json index 028cd21bf69..5c98066edf1 100644 --- a/service/imagebuilder/generated.json +++ b/service/imagebuilder/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/imagebuilder/go.mod b/service/imagebuilder/go.mod index ce8d71e784e..54dc70ee896 100644 --- a/service/imagebuilder/go.mod +++ b/service/imagebuilder/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/imagebuilder/internal/endpoints/endpoints.go b/service/imagebuilder/internal/endpoints/endpoints.go index 8f748643cf0..11eba25d6a7 100644 --- a/service/imagebuilder/internal/endpoints/endpoints.go +++ b/service/imagebuilder/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver imagebuilder endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "imagebuilder.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "imagebuilder-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "imagebuilder.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "imagebuilder.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "imagebuilder-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "imagebuilder.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "imagebuilder.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "imagebuilder.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "imagebuilder.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "imagebuilder.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "imagebuilder.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "imagebuilder-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "imagebuilder-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "imagebuilder.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/inspector/api_client.go b/service/inspector/api_client.go index c9646b3b0af..a91324fb3c1 100644 --- a/service/inspector/api_client.go +++ b/service/inspector/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/inspector/endpoints.go b/service/inspector/endpoints.go index 7a0aa716cce..9b20ec7f4e3 100644 --- a/service/inspector/endpoints.go +++ b/service/inspector/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/inspector/generated.json b/service/inspector/generated.json index 1153e8d29bf..6876277498c 100644 --- a/service/inspector/generated.json +++ b/service/inspector/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/inspector/go.mod b/service/inspector/go.mod index 527a2ce1541..5a89026ab75 100644 --- a/service/inspector/go.mod +++ b/service/inspector/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/inspector/internal/endpoints/endpoints.go b/service/inspector/internal/endpoints/endpoints.go index 9dcbe617859..e52b3352d20 100644 --- a/service/inspector/internal/endpoints/endpoints.go +++ b/service/inspector/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Inspector endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,106 +102,271 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "inspector.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "inspector.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "inspector-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "inspector.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "inspector.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "inspector.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "inspector-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "inspector.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "inspector.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "inspector.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "inspector.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "inspector.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "inspector.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "inspector.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "inspector-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "inspector.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "inspector-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "inspector-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/internal/benchmark/go.mod b/service/internal/benchmark/go.mod index d29e11132c2..8c682da0798 100644 --- a/service/internal/benchmark/go.mod +++ b/service/internal/benchmark/go.mod @@ -14,6 +14,8 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ diff --git a/service/internal/integrationtest/go.mod b/service/internal/integrationtest/go.mod index 74e616d3c13..1e2610f4022 100644 --- a/service/internal/integrationtest/go.mod +++ b/service/internal/integrationtest/go.mod @@ -101,6 +101,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/im replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/acm => ../../../service/acm/ diff --git a/service/iot/api_client.go b/service/iot/api_client.go index f2812512c37..552087542fa 100644 --- a/service/iot/api_client.go +++ b/service/iot/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/iot/endpoints.go b/service/iot/endpoints.go index 94f8732e168..ea4445b83d4 100644 --- a/service/iot/endpoints.go +++ b/service/iot/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iot/generated.json b/service/iot/generated.json index 2cc0e9f12d8..47c9e817ba0 100644 --- a/service/iot/generated.json +++ b/service/iot/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iot/go.mod b/service/iot/go.mod index f8ec64ed398..80fc3dcc9ec 100644 --- a/service/iot/go.mod +++ b/service/iot/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iot/internal/endpoints/endpoints.go b/service/iot/internal/endpoints/endpoints.go index 902a6da13b5..1fee670d37f 100644 --- a/service/iot/internal/endpoints/endpoints.go +++ b/service/iot/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,131 +102,348 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "execute-api", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: 0, + }: { + Hostname: "iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "iot-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iot.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "execute-api", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iot.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iot-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: 0, + }: { + Hostname: "iot.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iot.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iot.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iot.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iot.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "execute-api", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, + }, + { + Variant: 0, + }: { + Hostname: "iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "execute-api", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "iot-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "execute-api", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iot-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/iot1clickdevicesservice/api_client.go b/service/iot1clickdevicesservice/api_client.go index 086ccd2b53c..3062a79d1cd 100644 --- a/service/iot1clickdevicesservice/api_client.go +++ b/service/iot1clickdevicesservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iot1clickdevicesservice/endpoints.go b/service/iot1clickdevicesservice/endpoints.go index 755b8280943..39f540456e0 100644 --- a/service/iot1clickdevicesservice/endpoints.go +++ b/service/iot1clickdevicesservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iot1clickdevicesservice/generated.json b/service/iot1clickdevicesservice/generated.json index 4436eb6d804..c5e274e2b1b 100644 --- a/service/iot1clickdevicesservice/generated.json +++ b/service/iot1clickdevicesservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iot1clickdevicesservice/go.mod b/service/iot1clickdevicesservice/go.mod index 76f14e20047..81127f14834 100644 --- a/service/iot1clickdevicesservice/go.mod +++ b/service/iot1clickdevicesservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iot1clickdevicesservice/internal/endpoints/endpoints.go b/service/iot1clickdevicesservice/internal/endpoints/endpoints.go index 978b9b083d4..a322ed7817f 100644 --- a/service/iot1clickdevicesservice/internal/endpoints/endpoints.go +++ b/service/iot1clickdevicesservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT 1Click Devices Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "devices.iot1click.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devices.iot1click.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "devices.iot1click.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devices.iot1click.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "devices.iot1click.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devices.iot1click.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "devices.iot1click.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "devices.iot1click.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "devices.iot1click.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "devices.iot1click-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "devices.iot1click.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iot1clickprojects/api_client.go b/service/iot1clickprojects/api_client.go index c88336b763a..a0b9418b2d6 100644 --- a/service/iot1clickprojects/api_client.go +++ b/service/iot1clickprojects/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iot1clickprojects/endpoints.go b/service/iot1clickprojects/endpoints.go index 9c04110dc12..ac85d04c571 100644 --- a/service/iot1clickprojects/endpoints.go +++ b/service/iot1clickprojects/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iot1clickprojects/generated.json b/service/iot1clickprojects/generated.json index 9680e1955c0..344d24d9842 100644 --- a/service/iot1clickprojects/generated.json +++ b/service/iot1clickprojects/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iot1clickprojects/go.mod b/service/iot1clickprojects/go.mod index 38dc6a2d7be..99bdba1af11 100644 --- a/service/iot1clickprojects/go.mod +++ b/service/iot1clickprojects/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iot1clickprojects/internal/endpoints/endpoints.go b/service/iot1clickprojects/internal/endpoints/endpoints.go index dc31a8d8f53..899da9adda8 100644 --- a/service/iot1clickprojects/internal/endpoints/endpoints.go +++ b/service/iot1clickprojects/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT 1Click Projects endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "projects.iot1click.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "projects.iot1click.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "projects.iot1click.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "projects.iot1click.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "projects.iot1click.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "projects.iot1click.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "projects.iot1click.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "projects.iot1click.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "projects.iot1click.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "projects.iot1click-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "projects.iot1click.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotanalytics/api_client.go b/service/iotanalytics/api_client.go index 23873f9248a..db047462b62 100644 --- a/service/iotanalytics/api_client.go +++ b/service/iotanalytics/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotanalytics/endpoints.go b/service/iotanalytics/endpoints.go index 2c075463a19..dedc2d46fd2 100644 --- a/service/iotanalytics/endpoints.go +++ b/service/iotanalytics/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotanalytics/generated.json b/service/iotanalytics/generated.json index 3f324c3985c..8956a88f983 100644 --- a/service/iotanalytics/generated.json +++ b/service/iotanalytics/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotanalytics/go.mod b/service/iotanalytics/go.mod index fd333e870e8..3b01f3772c2 100644 --- a/service/iotanalytics/go.mod +++ b/service/iotanalytics/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotanalytics/internal/endpoints/endpoints.go b/service/iotanalytics/internal/endpoints/endpoints.go index e1529b0b23a..78cd3c9b64f 100644 --- a/service/iotanalytics/internal/endpoints/endpoints.go +++ b/service/iotanalytics/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoTAnalytics endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,164 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iotanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iotanalytics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotanalytics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotanalytics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iotanalytics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotanalytics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iotanalytics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotanalytics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iotanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotdataplane/api_client.go b/service/iotdataplane/api_client.go index b933030de28..40fe059fd5b 100644 --- a/service/iotdataplane/api_client.go +++ b/service/iotdataplane/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotdataplane/endpoints.go b/service/iotdataplane/endpoints.go index b1c7c36f845..ea30562f5ae 100644 --- a/service/iotdataplane/endpoints.go +++ b/service/iotdataplane/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotdataplane/generated.json b/service/iotdataplane/generated.json index a42b2ff85aa..16048d755d0 100644 --- a/service/iotdataplane/generated.json +++ b/service/iotdataplane/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotdataplane/go.mod b/service/iotdataplane/go.mod index 9a0cbaa748d..a7693d0aac1 100644 --- a/service/iotdataplane/go.mod +++ b/service/iotdataplane/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotdataplane/internal/endpoints/endpoints.go b/service/iotdataplane/internal/endpoints/endpoints.go index 3cd773b8ed7..c6c773536f2 100644 --- a/service/iotdataplane/internal/endpoints/endpoints.go +++ b/service/iotdataplane/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT Data Plane endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,131 +102,348 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "data.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "iotdata", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: 0, + }: { + Hostname: "data.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "data.iot.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "iotdata", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iot.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iot-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: 0, + }: { + Hostname: "data.iot.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "data.iot.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.iot.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "data.iot.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.iot.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "data.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "iotdata", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, + }, + { + Variant: 0, + }: { + Hostname: "data.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotdata", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "data.iot-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Service: "iotdata", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iot-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/iotdeviceadvisor/api_client.go b/service/iotdeviceadvisor/api_client.go index e76758fe8ff..b1aa7c0f925 100644 --- a/service/iotdeviceadvisor/api_client.go +++ b/service/iotdeviceadvisor/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotdeviceadvisor/endpoints.go b/service/iotdeviceadvisor/endpoints.go index 15c177ad0d2..56e2e039a92 100644 --- a/service/iotdeviceadvisor/endpoints.go +++ b/service/iotdeviceadvisor/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotdeviceadvisor/generated.json b/service/iotdeviceadvisor/generated.json index 437302ae6f2..d44d29ae3c2 100644 --- a/service/iotdeviceadvisor/generated.json +++ b/service/iotdeviceadvisor/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotdeviceadvisor/go.mod b/service/iotdeviceadvisor/go.mod index 79fa3b9e2c7..3490e0a3bcf 100644 --- a/service/iotdeviceadvisor/go.mod +++ b/service/iotdeviceadvisor/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotdeviceadvisor/internal/endpoints/endpoints.go b/service/iotdeviceadvisor/internal/endpoints/endpoints.go index 1dba70617a3..eef3d77d073 100644 --- a/service/iotdeviceadvisor/internal/endpoints/endpoints.go +++ b/service/iotdeviceadvisor/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IotDeviceAdvisor endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotdeviceadvisor.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.iotdeviceadvisor.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotdeviceadvisor.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.iotdeviceadvisor.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotdeviceadvisor-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotdeviceadvisor.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotevents/api_client.go b/service/iotevents/api_client.go index 7c0d18d9ed7..8dc86dfd464 100644 --- a/service/iotevents/api_client.go +++ b/service/iotevents/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotevents/endpoints.go b/service/iotevents/endpoints.go index 0f8a9e17658..7b72d8a539b 100644 --- a/service/iotevents/endpoints.go +++ b/service/iotevents/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotevents/generated.json b/service/iotevents/generated.json index 203f2ae4b03..5d92f96ffdb 100644 --- a/service/iotevents/generated.json +++ b/service/iotevents/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotevents/go.mod b/service/iotevents/go.mod index c21e41bc303..444e081dfe1 100644 --- a/service/iotevents/go.mod +++ b/service/iotevents/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotevents/internal/endpoints/endpoints.go b/service/iotevents/internal/endpoints/endpoints.go index 47841affe39..d09ffb13310 100644 --- a/service/iotevents/internal/endpoints/endpoints.go +++ b/service/iotevents/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT Events endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,71 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iotevents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotevents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotevents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotevents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotevents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iotevents.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotevents.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotevents-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotevents-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotevents.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iotevents.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotevents.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iotevents.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotevents.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iotevents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotevents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotevents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotevents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotevents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/ioteventsdata/api_client.go b/service/ioteventsdata/api_client.go index c0a1fb76c34..e312390a7a8 100644 --- a/service/ioteventsdata/api_client.go +++ b/service/ioteventsdata/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ioteventsdata/endpoints.go b/service/ioteventsdata/endpoints.go index a0bf84159d0..c2f3d303cd2 100644 --- a/service/ioteventsdata/endpoints.go +++ b/service/ioteventsdata/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ioteventsdata/generated.json b/service/ioteventsdata/generated.json index 923ffcbddab..d265b4fb14b 100644 --- a/service/ioteventsdata/generated.json +++ b/service/ioteventsdata/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ioteventsdata/go.mod b/service/ioteventsdata/go.mod index a3b82c63621..f0ec852c78a 100644 --- a/service/ioteventsdata/go.mod +++ b/service/ioteventsdata/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ioteventsdata/internal/endpoints/endpoints.go b/service/ioteventsdata/internal/endpoints/endpoints.go index ad53cf92baa..ac2931dc68e 100644 --- a/service/ioteventsdata/internal/endpoints/endpoints.go +++ b/service/ioteventsdata/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT Events Data endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "data.iotevents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iotevents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.iotevents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "data.iotevents.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iotevents-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.iotevents.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "data.iotevents.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.iotevents.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "data.iotevents.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.iotevents.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "data.iotevents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.iotevents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.iotevents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.iotevents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotfleethub/api_client.go b/service/iotfleethub/api_client.go index f5e54a7db2a..28e7ff6a6e7 100644 --- a/service/iotfleethub/api_client.go +++ b/service/iotfleethub/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/iotfleethub/endpoints.go b/service/iotfleethub/endpoints.go index 3ff88c18b5a..a5757a9df2e 100644 --- a/service/iotfleethub/endpoints.go +++ b/service/iotfleethub/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotfleethub/generated.json b/service/iotfleethub/generated.json index 60815ad1266..7ce51d36a5c 100644 --- a/service/iotfleethub/generated.json +++ b/service/iotfleethub/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotfleethub/go.mod b/service/iotfleethub/go.mod index 655a30099c8..72599e43a6b 100644 --- a/service/iotfleethub/go.mod +++ b/service/iotfleethub/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotfleethub/internal/endpoints/endpoints.go b/service/iotfleethub/internal/endpoints/endpoints.go index 707e997cd11..f0e5831201b 100644 --- a/service/iotfleethub/internal/endpoints/endpoints.go +++ b/service/iotfleethub/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoTFleetHub endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,89 +102,234 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.fleethub.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.fleethub.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "api.fleethub.iot-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "api.fleethub.iot-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "api.fleethub.iot-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "api.fleethub.iot-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.fleethub.iot.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.fleethub.iot.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.fleethub.iot.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.fleethub.iot.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.fleethub.iot.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.fleethub.iot.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.fleethub.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.fleethub.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.fleethub.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotjobsdataplane/api_client.go b/service/iotjobsdataplane/api_client.go index f7baaaa9d95..d6ee74fbb29 100644 --- a/service/iotjobsdataplane/api_client.go +++ b/service/iotjobsdataplane/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotjobsdataplane/endpoints.go b/service/iotjobsdataplane/endpoints.go index 05f725f51d6..5e67e838044 100644 --- a/service/iotjobsdataplane/endpoints.go +++ b/service/iotjobsdataplane/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotjobsdataplane/generated.json b/service/iotjobsdataplane/generated.json index 9eb71ea9377..ffc41502e94 100644 --- a/service/iotjobsdataplane/generated.json +++ b/service/iotjobsdataplane/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotjobsdataplane/go.mod b/service/iotjobsdataplane/go.mod index 8f22236bde9..6ef1cb159bc 100644 --- a/service/iotjobsdataplane/go.mod +++ b/service/iotjobsdataplane/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotjobsdataplane/internal/endpoints/endpoints.go b/service/iotjobsdataplane/internal/endpoints/endpoints.go index 1918c981e13..eb6d4b4c40c 100644 --- a/service/iotjobsdataplane/internal/endpoints/endpoints.go +++ b/service/iotjobsdataplane/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT Jobs Data Plane endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,122 +102,312 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "data.jobs.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.jobs.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "data.jobs.iot.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.jobs.iot.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "data.jobs.iot.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.jobs.iot.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "data.jobs.iot.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.jobs.iot.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "data.jobs.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.jobs.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.jobs.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "data.jobs.iot-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.jobs.iot-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/iotsecuretunneling/api_client.go b/service/iotsecuretunneling/api_client.go index f6e930dfe3a..c3f0f23c682 100644 --- a/service/iotsecuretunneling/api_client.go +++ b/service/iotsecuretunneling/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotsecuretunneling/endpoints.go b/service/iotsecuretunneling/endpoints.go index 003ac046fd4..015d7e168ba 100644 --- a/service/iotsecuretunneling/endpoints.go +++ b/service/iotsecuretunneling/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotsecuretunneling/generated.json b/service/iotsecuretunneling/generated.json index 8b2e89285c2..9397236293d 100644 --- a/service/iotsecuretunneling/generated.json +++ b/service/iotsecuretunneling/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotsecuretunneling/go.mod b/service/iotsecuretunneling/go.mod index 8db41afebbb..8025df1928d 100644 --- a/service/iotsecuretunneling/go.mod +++ b/service/iotsecuretunneling/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotsecuretunneling/internal/endpoints/endpoints.go b/service/iotsecuretunneling/internal/endpoints/endpoints.go index 212fe083de8..f11f21d3164 100644 --- a/service/iotsecuretunneling/internal/endpoints/endpoints.go +++ b/service/iotsecuretunneling/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoTSecureTunneling endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.tunneling.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.tunneling.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.tunneling.iot.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.tunneling.iot.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.tunneling.iot.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.tunneling.iot.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.tunneling.iot.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.tunneling.iot.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.tunneling.iot.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.tunneling.iot-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.tunneling.iot.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotsitewise/api_client.go b/service/iotsitewise/api_client.go index 7ecb00fa446..8ccbafad386 100644 --- a/service/iotsitewise/api_client.go +++ b/service/iotsitewise/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/iotsitewise/endpoints.go b/service/iotsitewise/endpoints.go index b8304031b29..e2e86888876 100644 --- a/service/iotsitewise/endpoints.go +++ b/service/iotsitewise/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotsitewise/generated.json b/service/iotsitewise/generated.json index 640cf55b5de..bc6f75e85f1 100644 --- a/service/iotsitewise/generated.json +++ b/service/iotsitewise/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/iotsitewise/go.mod b/service/iotsitewise/go.mod index 3837a47662e..27808722920 100644 --- a/service/iotsitewise/go.mod +++ b/service/iotsitewise/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotsitewise/internal/endpoints/endpoints.go b/service/iotsitewise/internal/endpoints/endpoints.go index 458bede3154..f8897cca569 100644 --- a/service/iotsitewise/internal/endpoints/endpoints.go +++ b/service/iotsitewise/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoTSiteWise endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,174 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iotsitewise.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotsitewise-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotsitewise.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iotsitewise.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotsitewise-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotsitewise.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iotsitewise.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotsitewise.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iotsitewise.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotsitewise.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iotsitewise.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotsitewise-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotsitewise-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotsitewise.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + }, }, } diff --git a/service/iotthingsgraph/api_client.go b/service/iotthingsgraph/api_client.go index 4e75508b0d9..add2c56684f 100644 --- a/service/iotthingsgraph/api_client.go +++ b/service/iotthingsgraph/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/iotthingsgraph/endpoints.go b/service/iotthingsgraph/endpoints.go index 2aa81f7302c..88e0c2feddd 100644 --- a/service/iotthingsgraph/endpoints.go +++ b/service/iotthingsgraph/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotthingsgraph/generated.json b/service/iotthingsgraph/generated.json index 4cd5331580f..5aeeaa5faed 100644 --- a/service/iotthingsgraph/generated.json +++ b/service/iotthingsgraph/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotthingsgraph/go.mod b/service/iotthingsgraph/go.mod index 07dc3bc26d2..6b35b32763a 100644 --- a/service/iotthingsgraph/go.mod +++ b/service/iotthingsgraph/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotthingsgraph/internal/endpoints/endpoints.go b/service/iotthingsgraph/internal/endpoints/endpoints.go index 3a3132cc83f..9be009dea48 100644 --- a/service/iotthingsgraph/internal/endpoints/endpoints.go +++ b/service/iotthingsgraph/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoTThingsGraph endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,165 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "iotthingsgraph.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "iotthingsgraph", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotthingsgraph", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotthingsgraph", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotthingsgraph", + }, + }, + { + Variant: 0, + }: { + Hostname: "iotthingsgraph.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "iotthingsgraph", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "iotthingsgraph.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotthingsgraph.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "iotthingsgraph.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotthingsgraph.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "iotthingsgraph.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "iotthingsgraph.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "iotthingsgraph.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "iotthingsgraph-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "iotthingsgraph.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/iotwireless/api_client.go b/service/iotwireless/api_client.go index 3f53419e7f4..8f9509d0967 100644 --- a/service/iotwireless/api_client.go +++ b/service/iotwireless/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/iotwireless/endpoints.go b/service/iotwireless/endpoints.go index be577502889..063aee11849 100644 --- a/service/iotwireless/endpoints.go +++ b/service/iotwireless/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/iotwireless/generated.json b/service/iotwireless/generated.json index 605d3a2286c..55f7dc228f3 100644 --- a/service/iotwireless/generated.json +++ b/service/iotwireless/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/iotwireless/go.mod b/service/iotwireless/go.mod index 9f96815a15f..12cecb95fdf 100644 --- a/service/iotwireless/go.mod +++ b/service/iotwireless/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/iotwireless/internal/endpoints/endpoints.go b/service/iotwireless/internal/endpoints/endpoints.go index 715993c60e6..b51c49c163e 100644 --- a/service/iotwireless/internal/endpoints/endpoints.go +++ b/service/iotwireless/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver IoT Wireless endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotwireless.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotwireless.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotwireless.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotwireless.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotwireless.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.iotwireless.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotwireless.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.iotwireless.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.iotwireless.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.iotwireless-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.iotwireless.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/ivs/api_client.go b/service/ivs/api_client.go index b1b875534a8..684aa8b9c1d 100644 --- a/service/ivs/api_client.go +++ b/service/ivs/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ivs/endpoints.go b/service/ivs/endpoints.go index bcef4b0c08a..0b48f8a9ab0 100644 --- a/service/ivs/endpoints.go +++ b/service/ivs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ivs/generated.json b/service/ivs/generated.json index 333c51a7f18..201d8ff3863 100644 --- a/service/ivs/generated.json +++ b/service/ivs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ivs/go.mod b/service/ivs/go.mod index 8db9e64c949..0ae85ddee1e 100644 --- a/service/ivs/go.mod +++ b/service/ivs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ivs/internal/endpoints/endpoints.go b/service/ivs/internal/endpoints/endpoints.go index e17ecb83889..f7d5e3f5866 100644 --- a/service/ivs/internal/endpoints/endpoints.go +++ b/service/ivs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ivs endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,55 +102,144 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ivs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ivs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ivs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ivs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ivs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ivs.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ivs.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ivs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ivs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ivs.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ivs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ivs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ivs.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ivs.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ivs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ivs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ivs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ivs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ivs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kafka/api_client.go b/service/kafka/api_client.go index 1bf87701f48..8b4c21a7d25 100644 --- a/service/kafka/api_client.go +++ b/service/kafka/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kafka/endpoints.go b/service/kafka/endpoints.go index 2ddb6310b73..1b36596bfc5 100644 --- a/service/kafka/endpoints.go +++ b/service/kafka/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kafka/generated.json b/service/kafka/generated.json index 9b2d36860a5..a849698151c 100644 --- a/service/kafka/generated.json +++ b/service/kafka/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kafka/go.mod b/service/kafka/go.mod index 72b71287bc2..ca4e3e5f181 100644 --- a/service/kafka/go.mod +++ b/service/kafka/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kafka/internal/endpoints/endpoints.go b/service/kafka/internal/endpoints/endpoints.go index 10228a91db0..9bbdc7c3eb1 100644 --- a/service/kafka/internal/endpoints/endpoints.go +++ b/service/kafka/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kafka endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,81 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kafka.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafka.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafka-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafka-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafka.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kafka.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafka.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafka-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafka-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafka.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kafka.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kafka.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kafka.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kafka.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kafka.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafka.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafka-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafka-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafka.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/kafkaconnect/api_client.go b/service/kafkaconnect/api_client.go index 97549fd2ca0..d4e59f10a85 100644 --- a/service/kafkaconnect/api_client.go +++ b/service/kafkaconnect/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kafkaconnect/endpoints.go b/service/kafkaconnect/endpoints.go index 421c96d6d54..df9542db671 100644 --- a/service/kafkaconnect/endpoints.go +++ b/service/kafkaconnect/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kafkaconnect/generated.json b/service/kafkaconnect/generated.json index f69df3fa947..542c3ecb385 100644 --- a/service/kafkaconnect/generated.json +++ b/service/kafkaconnect/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kafkaconnect/go.mod b/service/kafkaconnect/go.mod index 9ccc5e4fe95..939971ccb41 100644 --- a/service/kafkaconnect/go.mod +++ b/service/kafkaconnect/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kafkaconnect/internal/endpoints/endpoints.go b/service/kafkaconnect/internal/endpoints/endpoints.go index 1547dd14885..58096f246f8 100644 --- a/service/kafkaconnect/internal/endpoints/endpoints.go +++ b/service/kafkaconnect/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver KafkaConnect endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,68 +102,183 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kafkaconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafkaconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kafkaconnect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafkaconnect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kafkaconnect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kafkaconnect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kafkaconnect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kafkaconnect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kafkaconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kafkaconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kafkaconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kendra/api_client.go b/service/kendra/api_client.go index 29332da5d08..784c9a197f7 100644 --- a/service/kendra/api_client.go +++ b/service/kendra/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/kendra/endpoints.go b/service/kendra/endpoints.go index a3eb8dd4cc4..686f0beade0 100644 --- a/service/kendra/endpoints.go +++ b/service/kendra/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kendra/generated.json b/service/kendra/generated.json index 65a58d6491d..c6f56ce2611 100644 --- a/service/kendra/generated.json +++ b/service/kendra/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kendra/go.mod b/service/kendra/go.mod index 75b4e0b5c8e..62fc0ee498b 100644 --- a/service/kendra/go.mod +++ b/service/kendra/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kendra/internal/endpoints/endpoints.go b/service/kendra/internal/endpoints/endpoints.go index a1367055c99..1ae463b0ebf 100644 --- a/service/kendra/internal/endpoints/endpoints.go +++ b/service/kendra/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver kendra endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,82 +102,223 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kendra.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kendra.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kendra-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kendra.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "kendra-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "kendra-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "kendra-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kendra.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kendra.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kendra-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kendra.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kendra.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kendra.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kendra.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kendra.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kendra.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kendra.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kendra-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kendra.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "kendra-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kendra-fips.us-gov-west-1.amazonaws.com", + }, }, }, } diff --git a/service/kinesis/api_client.go b/service/kinesis/api_client.go index 44c9074f9ef..d246abf779f 100644 --- a/service/kinesis/api_client.go +++ b/service/kinesis/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesis/endpoints.go b/service/kinesis/endpoints.go index 8a471997657..2a797681195 100644 --- a/service/kinesis/endpoints.go +++ b/service/kinesis/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesis/generated.json b/service/kinesis/generated.json index 71a27e4d77a..728235707aa 100644 --- a/service/kinesis/generated.json +++ b/service/kinesis/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/kinesis/go.mod b/service/kinesis/go.mod index 331ef22c222..5fd8b3e6729 100644 --- a/service/kinesis/go.mod +++ b/service/kinesis/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesis/internal/endpoints/endpoints.go b/service/kinesis/internal/endpoints/endpoints.go index 0bbfac01096..c2ab2a40033 100644 --- a/service/kinesis/internal/endpoints/endpoints.go +++ b/service/kinesis/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesis.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesis.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesis-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesis.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "kinesis-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "kinesis-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "kinesis-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "kinesis-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesis.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesis.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesis-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesis.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesis.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesis.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesis.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesis.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesis.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesis.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesis-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesis-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesis.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "kinesis.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "kinesis.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/kinesisanalytics/api_client.go b/service/kinesisanalytics/api_client.go index eadfd7b61a8..0a5ea458cd0 100644 --- a/service/kinesisanalytics/api_client.go +++ b/service/kinesisanalytics/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisanalytics/endpoints.go b/service/kinesisanalytics/endpoints.go index 4d0678579fc..95983a2b028 100644 --- a/service/kinesisanalytics/endpoints.go +++ b/service/kinesisanalytics/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisanalytics/generated.json b/service/kinesisanalytics/generated.json index d426125a1d2..7f221f705c0 100644 --- a/service/kinesisanalytics/generated.json +++ b/service/kinesisanalytics/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisanalytics/go.mod b/service/kinesisanalytics/go.mod index d5b2abc12ff..c46a6e749fd 100644 --- a/service/kinesisanalytics/go.mod +++ b/service/kinesisanalytics/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisanalytics/internal/endpoints/endpoints.go b/service/kinesisanalytics/internal/endpoints/endpoints.go index 170b8c03d1d..a2432d60e2d 100644 --- a/service/kinesisanalytics/internal/endpoints/endpoints.go +++ b/service/kinesisanalytics/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Analytics endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,81 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/kinesisanalyticsv2/api_client.go b/service/kinesisanalyticsv2/api_client.go index 6afbc3e2cef..f6296889684 100644 --- a/service/kinesisanalyticsv2/api_client.go +++ b/service/kinesisanalyticsv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisanalyticsv2/endpoints.go b/service/kinesisanalyticsv2/endpoints.go index 2e88c5e977f..a18726a5e3e 100644 --- a/service/kinesisanalyticsv2/endpoints.go +++ b/service/kinesisanalyticsv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisanalyticsv2/generated.json b/service/kinesisanalyticsv2/generated.json index 57ef12abb8f..ee488fe415f 100644 --- a/service/kinesisanalyticsv2/generated.json +++ b/service/kinesisanalyticsv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisanalyticsv2/go.mod b/service/kinesisanalyticsv2/go.mod index 1d6238d74ea..8b1b2eceac3 100644 --- a/service/kinesisanalyticsv2/go.mod +++ b/service/kinesisanalyticsv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisanalyticsv2/internal/endpoints/endpoints.go b/service/kinesisanalyticsv2/internal/endpoints/endpoints.go index c6ebdb2a6c4..7e06b00adf3 100644 --- a/service/kinesisanalyticsv2/internal/endpoints/endpoints.go +++ b/service/kinesisanalyticsv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Analytics V2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,81 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/kinesisvideo/api_client.go b/service/kinesisvideo/api_client.go index 26d14e1d865..96b16fe6519 100644 --- a/service/kinesisvideo/api_client.go +++ b/service/kinesisvideo/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisvideo/endpoints.go b/service/kinesisvideo/endpoints.go index 04714f9e3d6..95ae60e4c96 100644 --- a/service/kinesisvideo/endpoints.go +++ b/service/kinesisvideo/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisvideo/generated.json b/service/kinesisvideo/generated.json index 54ec220ae37..a904610230d 100644 --- a/service/kinesisvideo/generated.json +++ b/service/kinesisvideo/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisvideo/go.mod b/service/kinesisvideo/go.mod index e6feaab9899..7dfd7bc8640 100644 --- a/service/kinesisvideo/go.mod +++ b/service/kinesisvideo/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisvideo/internal/endpoints/endpoints.go b/service/kinesisvideo/internal/endpoints/endpoints.go index 9df52df279b..c26b522a130 100644 --- a/service/kinesisvideo/internal/endpoints/endpoints.go +++ b/service/kinesisvideo/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Video endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kinesisvideoarchivedmedia/api_client.go b/service/kinesisvideoarchivedmedia/api_client.go index b0f86b5be97..5b6a0d53763 100644 --- a/service/kinesisvideoarchivedmedia/api_client.go +++ b/service/kinesisvideoarchivedmedia/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisvideoarchivedmedia/endpoints.go b/service/kinesisvideoarchivedmedia/endpoints.go index 7a1494d88dd..faa783a87f0 100644 --- a/service/kinesisvideoarchivedmedia/endpoints.go +++ b/service/kinesisvideoarchivedmedia/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisvideoarchivedmedia/generated.json b/service/kinesisvideoarchivedmedia/generated.json index dd044a24024..45e8f812d20 100644 --- a/service/kinesisvideoarchivedmedia/generated.json +++ b/service/kinesisvideoarchivedmedia/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisvideoarchivedmedia/go.mod b/service/kinesisvideoarchivedmedia/go.mod index 5590a43389f..d81a83f86db 100644 --- a/service/kinesisvideoarchivedmedia/go.mod +++ b/service/kinesisvideoarchivedmedia/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisvideoarchivedmedia/internal/endpoints/endpoints.go b/service/kinesisvideoarchivedmedia/internal/endpoints/endpoints.go index 9eb7eeae9dc..59a79d5e0b1 100644 --- a/service/kinesisvideoarchivedmedia/internal/endpoints/endpoints.go +++ b/service/kinesisvideoarchivedmedia/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Video Archived Media endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kinesisvideomedia/api_client.go b/service/kinesisvideomedia/api_client.go index a451a14318f..052e21fc7e7 100644 --- a/service/kinesisvideomedia/api_client.go +++ b/service/kinesisvideomedia/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisvideomedia/endpoints.go b/service/kinesisvideomedia/endpoints.go index f03c4469c91..4b341d9c3cc 100644 --- a/service/kinesisvideomedia/endpoints.go +++ b/service/kinesisvideomedia/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisvideomedia/generated.json b/service/kinesisvideomedia/generated.json index 2b7aefa7bd1..83fbea6f43c 100644 --- a/service/kinesisvideomedia/generated.json +++ b/service/kinesisvideomedia/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisvideomedia/go.mod b/service/kinesisvideomedia/go.mod index 8e2f7bbd345..d17c5861ced 100644 --- a/service/kinesisvideomedia/go.mod +++ b/service/kinesisvideomedia/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisvideomedia/internal/endpoints/endpoints.go b/service/kinesisvideomedia/internal/endpoints/endpoints.go index 6dbbc9b7793..209fdc6fdb5 100644 --- a/service/kinesisvideomedia/internal/endpoints/endpoints.go +++ b/service/kinesisvideomedia/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Video Media endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kinesisvideosignaling/api_client.go b/service/kinesisvideosignaling/api_client.go index e492dbd66aa..5e7f3dd1f5a 100644 --- a/service/kinesisvideosignaling/api_client.go +++ b/service/kinesisvideosignaling/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kinesisvideosignaling/endpoints.go b/service/kinesisvideosignaling/endpoints.go index 2e421dae252..3d54a4bf725 100644 --- a/service/kinesisvideosignaling/endpoints.go +++ b/service/kinesisvideosignaling/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kinesisvideosignaling/generated.json b/service/kinesisvideosignaling/generated.json index 372c4159155..fe2535e09cc 100644 --- a/service/kinesisvideosignaling/generated.json +++ b/service/kinesisvideosignaling/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kinesisvideosignaling/go.mod b/service/kinesisvideosignaling/go.mod index d271da07c18..1c6d744e47d 100644 --- a/service/kinesisvideosignaling/go.mod +++ b/service/kinesisvideosignaling/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kinesisvideosignaling/internal/endpoints/endpoints.go b/service/kinesisvideosignaling/internal/endpoints/endpoints.go index 1ae7f41b3c3..da56485ffee 100644 --- a/service/kinesisvideosignaling/internal/endpoints/endpoints.go +++ b/service/kinesisvideosignaling/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Kinesis Video Signaling endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kinesisvideo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kinesisvideo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kinesisvideo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/kms/api_client.go b/service/kms/api_client.go index d613c9ac648..baa3c4f402e 100644 --- a/service/kms/api_client.go +++ b/service/kms/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/kms/endpoints.go b/service/kms/endpoints.go index b8bce7e926b..43b65e982c4 100644 --- a/service/kms/endpoints.go +++ b/service/kms/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/kms/generated.json b/service/kms/generated.json index 1393f87785a..7575f7927bf 100644 --- a/service/kms/generated.json +++ b/service/kms/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/kms/go.mod b/service/kms/go.mod index 2374a2af28c..0062a323919 100644 --- a/service/kms/go.mod +++ b/service/kms/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/kms/internal/endpoints/endpoints.go b/service/kms/internal/endpoints/endpoints.go index 4ee8142bbf5..6d36808a5af 100644 --- a/service/kms/internal/endpoints/endpoints.go +++ b/service/kms/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver KMS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,108 +102,253 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "kms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "kms.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kms.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kms-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kms-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kms.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "kms.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kms.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ProdFips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ProdFips", + }: endpoints.Endpoint{ Hostname: "kms-fips.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", }, }, - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "kms.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "kms.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ProdFips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ProdFips", + }: endpoints.Endpoint{ Hostname: "kms-fips.us-isob-east-1.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", }, }, - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "kms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "kms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "kms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "kms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "kms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ProdFips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ProdFips", + }: endpoints.Endpoint{ Hostname: "kms-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/lakeformation/api_client.go b/service/lakeformation/api_client.go index 55f565da824..e453ac9e8a6 100644 --- a/service/lakeformation/api_client.go +++ b/service/lakeformation/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lakeformation/endpoints.go b/service/lakeformation/endpoints.go index 10efeb2a916..ebf32fdff33 100644 --- a/service/lakeformation/endpoints.go +++ b/service/lakeformation/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lakeformation/generated.json b/service/lakeformation/generated.json index 94c5e8a54f8..4dfdcfbe265 100644 --- a/service/lakeformation/generated.json +++ b/service/lakeformation/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lakeformation/go.mod b/service/lakeformation/go.mod index 69e465c27a3..00a3f4479c8 100644 --- a/service/lakeformation/go.mod +++ b/service/lakeformation/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lakeformation/internal/endpoints/endpoints.go b/service/lakeformation/internal/endpoints/endpoints.go index 024e58dcd81..db99e4a911c 100644 --- a/service/lakeformation/internal/endpoints/endpoints.go +++ b/service/lakeformation/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver LakeFormation endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,112 +102,288 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lakeformation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lakeformation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lakeformation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lakeformation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "lakeformation-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "lakeformation-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "lakeformation-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "lakeformation-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lakeformation.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lakeformation.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lakeformation-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lakeformation.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lakeformation.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lakeformation.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lakeformation.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lakeformation.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lakeformation.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lakeformation.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lakeformation-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lakeformation.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "lakeformation-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lakeformation-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/lambda/api_client.go b/service/lambda/api_client.go index 0b422cf1fa3..910b87d4c9c 100644 --- a/service/lambda/api_client.go +++ b/service/lambda/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lambda/endpoints.go b/service/lambda/endpoints.go index b76161a0353..123af23ed68 100644 --- a/service/lambda/endpoints.go +++ b/service/lambda/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lambda/generated.json b/service/lambda/generated.json index 277a058dbe8..570b86993ae 100644 --- a/service/lambda/generated.json +++ b/service/lambda/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/lambda/go.mod b/service/lambda/go.mod index 8db0931e2c3..8c13433dc29 100644 --- a/service/lambda/go.mod +++ b/service/lambda/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lambda/internal/endpoints/endpoints.go b/service/lambda/internal/endpoints/endpoints.go index 3fc5f8c9e6b..23a56e83e1f 100644 --- a/service/lambda/internal/endpoints/endpoints.go +++ b/service/lambda/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lambda endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lambda.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lambda.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lambda-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lambda.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lambda.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lambda.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lambda-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lambda.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lambda.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lambda.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lambda.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lambda.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lambda.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lambda.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lambda-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lambda.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "lambda-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lambda-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/lexmodelbuildingservice/api_client.go b/service/lexmodelbuildingservice/api_client.go index 6ffbd6d0e54..593bf54ea03 100644 --- a/service/lexmodelbuildingservice/api_client.go +++ b/service/lexmodelbuildingservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lexmodelbuildingservice/endpoints.go b/service/lexmodelbuildingservice/endpoints.go index dc5e8915199..d9f8a589fa7 100644 --- a/service/lexmodelbuildingservice/endpoints.go +++ b/service/lexmodelbuildingservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lexmodelbuildingservice/generated.json b/service/lexmodelbuildingservice/generated.json index 0a5fabc7a65..e909ffdabf6 100644 --- a/service/lexmodelbuildingservice/generated.json +++ b/service/lexmodelbuildingservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lexmodelbuildingservice/go.mod b/service/lexmodelbuildingservice/go.mod index 8053a84206b..d13ea276562 100644 --- a/service/lexmodelbuildingservice/go.mod +++ b/service/lexmodelbuildingservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lexmodelbuildingservice/internal/endpoints/endpoints.go b/service/lexmodelbuildingservice/internal/endpoints/endpoints.go index 2082eaa0c6e..3ec8a6989ce 100644 --- a/service/lexmodelbuildingservice/internal/endpoints/endpoints.go +++ b/service/lexmodelbuildingservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lex Model Building Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,88 +102,234 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "models.lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "lex", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models.lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models.lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models.lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: 0, + }: { + Hostname: "models.lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-fips.lex.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "models-fips.lex.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-fips.lex.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "models-fips.lex.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "models.lex.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models.lex.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models.lex-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models.lex-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "models.lex.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "models.lex.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "models.lex.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "models.lex.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "models.lex.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "models.lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "lex", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models.lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models.lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models.lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: 0, + }: { + Hostname: "models.lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-fips.lex.us-gov-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "models-fips.lex.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/lexmodelsv2/api_client.go b/service/lexmodelsv2/api_client.go index 2f949156bea..2b295fd9579 100644 --- a/service/lexmodelsv2/api_client.go +++ b/service/lexmodelsv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lexmodelsv2/endpoints.go b/service/lexmodelsv2/endpoints.go index e350165ce1e..0501641e5d1 100644 --- a/service/lexmodelsv2/endpoints.go +++ b/service/lexmodelsv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lexmodelsv2/generated.json b/service/lexmodelsv2/generated.json index b1809a4e943..3fd88696111 100644 --- a/service/lexmodelsv2/generated.json +++ b/service/lexmodelsv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/lexmodelsv2/go.mod b/service/lexmodelsv2/go.mod index 104e892e360..dbf1e78ea8c 100644 --- a/service/lexmodelsv2/go.mod +++ b/service/lexmodelsv2/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lexmodelsv2/internal/endpoints/endpoints.go b/service/lexmodelsv2/internal/endpoints/endpoints.go index 93647868b24..ec6d36b33af 100644 --- a/service/lexmodelsv2/internal/endpoints/endpoints.go +++ b/service/lexmodelsv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lex Models V2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,168 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "models-v2-lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "models-v2-lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "models-v2-lex.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "models-v2-lex.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "models-v2-lex.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "models-v2-lex.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "models-v2-lex.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "models-v2-lex.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "models-v2-lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "models-v2-lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "models-v2-lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/lexruntimeservice/api_client.go b/service/lexruntimeservice/api_client.go index eff7a3f5e52..fd24ea3a330 100644 --- a/service/lexruntimeservice/api_client.go +++ b/service/lexruntimeservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lexruntimeservice/endpoints.go b/service/lexruntimeservice/endpoints.go index 942a3d670db..fd3274ddce8 100644 --- a/service/lexruntimeservice/endpoints.go +++ b/service/lexruntimeservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lexruntimeservice/generated.json b/service/lexruntimeservice/generated.json index 298b50456e2..3844ec89697 100644 --- a/service/lexruntimeservice/generated.json +++ b/service/lexruntimeservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lexruntimeservice/go.mod b/service/lexruntimeservice/go.mod index 864a43012cf..d23550e9edc 100644 --- a/service/lexruntimeservice/go.mod +++ b/service/lexruntimeservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lexruntimeservice/internal/endpoints/endpoints.go b/service/lexruntimeservice/internal/endpoints/endpoints.go index 15a55ffffdf..15750e1365c 100644 --- a/service/lexruntimeservice/internal/endpoints/endpoints.go +++ b/service/lexruntimeservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lex Runtime Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,88 +102,234 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "lex", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: 0, + }: { + Hostname: "runtime.lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.lex.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.lex.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.lex.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.lex.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.lex.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.lex-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime.lex.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.lex.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime.lex.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.lex.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime.lex.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "lex", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, + }, + { + Variant: 0, + }: { + Hostname: "runtime.lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "lex", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.lex.us-gov-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.lex.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/lexruntimev2/api_client.go b/service/lexruntimev2/api_client.go index 2e9854d29b7..17800675b3c 100644 --- a/service/lexruntimev2/api_client.go +++ b/service/lexruntimev2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lexruntimev2/endpoints.go b/service/lexruntimev2/endpoints.go index 967ff488afa..4d4907d0105 100644 --- a/service/lexruntimev2/endpoints.go +++ b/service/lexruntimev2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lexruntimev2/generated.json b/service/lexruntimev2/generated.json index 74c19945835..87e494640ae 100644 --- a/service/lexruntimev2/generated.json +++ b/service/lexruntimev2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lexruntimev2/go.mod b/service/lexruntimev2/go.mod index 30fbe8f3d53..349b6951863 100644 --- a/service/lexruntimev2/go.mod +++ b/service/lexruntimev2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lexruntimev2/internal/endpoints/endpoints.go b/service/lexruntimev2/internal/endpoints/endpoints.go index aa861590645..0e3e25ff3c3 100644 --- a/service/lexruntimev2/internal/endpoints/endpoints.go +++ b/service/lexruntimev2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lex Runtime V2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,168 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "runtime-v2-lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime-v2-lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "runtime-v2-lex.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime-v2-lex.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "runtime-v2-lex.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime-v2-lex.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "runtime-v2-lex.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime-v2-lex.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "runtime-v2-lex.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime-v2-lex-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime-v2-lex.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/licensemanager/api_client.go b/service/licensemanager/api_client.go index 028a3ce4902..23f2ad1aedc 100644 --- a/service/licensemanager/api_client.go +++ b/service/licensemanager/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/licensemanager/endpoints.go b/service/licensemanager/endpoints.go index f577230d86b..38c39442da5 100644 --- a/service/licensemanager/endpoints.go +++ b/service/licensemanager/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/licensemanager/generated.json b/service/licensemanager/generated.json index 7ed2165c1ac..088d7c0ca8a 100644 --- a/service/licensemanager/generated.json +++ b/service/licensemanager/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/licensemanager/go.mod b/service/licensemanager/go.mod index 03df94a1bc9..ded39d52ef6 100644 --- a/service/licensemanager/go.mod +++ b/service/licensemanager/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/licensemanager/internal/endpoints/endpoints.go b/service/licensemanager/internal/endpoints/endpoints.go index 72b6b8ab6fb..cb57d69b9d3 100644 --- a/service/licensemanager/internal/endpoints/endpoints.go +++ b/service/licensemanager/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver License Manager endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,125 +102,316 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "license-manager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "license-manager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "license-manager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "license-manager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "license-manager.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "license-manager.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "license-manager-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "license-manager.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "license-manager.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "license-manager.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "license-manager.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "license-manager.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "license-manager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "license-manager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "license-manager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "license-manager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "license-manager-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "license-manager-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/lightsail/api_client.go b/service/lightsail/api_client.go index d4d882688b5..e601121dc4f 100644 --- a/service/lightsail/api_client.go +++ b/service/lightsail/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lightsail/endpoints.go b/service/lightsail/endpoints.go index 77542217ad8..7544a6b8b09 100644 --- a/service/lightsail/endpoints.go +++ b/service/lightsail/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lightsail/generated.json b/service/lightsail/generated.json index 3e78d9d425d..65a0ce3c18f 100644 --- a/service/lightsail/generated.json +++ b/service/lightsail/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lightsail/go.mod b/service/lightsail/go.mod index 3b166df9bad..251dc3994c7 100644 --- a/service/lightsail/go.mod +++ b/service/lightsail/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lightsail/internal/endpoints/endpoints.go b/service/lightsail/internal/endpoints/endpoints.go index daffa6e3e7f..dfc44ed1cec 100644 --- a/service/lightsail/internal/endpoints/endpoints.go +++ b/service/lightsail/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Lightsail endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,66 +102,177 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lightsail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lightsail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lightsail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lightsail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lightsail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lightsail.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lightsail.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lightsail-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lightsail-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lightsail.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lightsail.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lightsail.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lightsail.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lightsail.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lightsail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lightsail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lightsail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lightsail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lightsail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/location/api_client.go b/service/location/api_client.go index 95670dab54c..d5f3c7d8747 100644 --- a/service/location/api_client.go +++ b/service/location/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/location/endpoints.go b/service/location/endpoints.go index f75f80c824e..25f4632d7cd 100644 --- a/service/location/endpoints.go +++ b/service/location/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/location/generated.json b/service/location/generated.json index c879b11ea97..38ef0a35c57 100644 --- a/service/location/generated.json +++ b/service/location/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/location/go.mod b/service/location/go.mod index 89b75b0acd9..d9861faaf3f 100644 --- a/service/location/go.mod +++ b/service/location/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/location/internal/endpoints/endpoints.go b/service/location/internal/endpoints/endpoints.go index 81ac632797e..aeed84206c7 100644 --- a/service/location/internal/endpoints/endpoints.go +++ b/service/location/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Location endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "geo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "geo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "geo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "geo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "geo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "geo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "geo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "geo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "geo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "geo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "geo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "geo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "geo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "geo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "geo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "geo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "geo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "geo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "geo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/lookoutequipment/api_client.go b/service/lookoutequipment/api_client.go index 8c1c8dab329..1ebadc5d5fd 100644 --- a/service/lookoutequipment/api_client.go +++ b/service/lookoutequipment/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/lookoutequipment/endpoints.go b/service/lookoutequipment/endpoints.go index 3116d8e84df..f059734e17f 100644 --- a/service/lookoutequipment/endpoints.go +++ b/service/lookoutequipment/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lookoutequipment/generated.json b/service/lookoutequipment/generated.json index 2a6b4245343..4386d0c2b94 100644 --- a/service/lookoutequipment/generated.json +++ b/service/lookoutequipment/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lookoutequipment/go.mod b/service/lookoutequipment/go.mod index 8ae1181a73d..3e684b96118 100644 --- a/service/lookoutequipment/go.mod +++ b/service/lookoutequipment/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lookoutequipment/internal/endpoints/endpoints.go b/service/lookoutequipment/internal/endpoints/endpoints.go index e0a2bc8771b..d295399ac41 100644 --- a/service/lookoutequipment/internal/endpoints/endpoints.go +++ b/service/lookoutequipment/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver LookoutEquipment endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,55 +102,144 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutequipment.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutequipment.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutequipment.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutequipment.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutequipment.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutequipment.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutequipment.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutequipment.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutequipment.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutequipment-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutequipment.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/lookoutmetrics/api_client.go b/service/lookoutmetrics/api_client.go index 2490231b04d..6ab72ee1fbc 100644 --- a/service/lookoutmetrics/api_client.go +++ b/service/lookoutmetrics/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/lookoutmetrics/endpoints.go b/service/lookoutmetrics/endpoints.go index 756f78d1bac..c4a1c5b98f0 100644 --- a/service/lookoutmetrics/endpoints.go +++ b/service/lookoutmetrics/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lookoutmetrics/generated.json b/service/lookoutmetrics/generated.json index a89de82639d..932d12a7c22 100644 --- a/service/lookoutmetrics/generated.json +++ b/service/lookoutmetrics/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lookoutmetrics/go.mod b/service/lookoutmetrics/go.mod index 6c92c903a8b..af4850f8a24 100644 --- a/service/lookoutmetrics/go.mod +++ b/service/lookoutmetrics/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lookoutmetrics/internal/endpoints/endpoints.go b/service/lookoutmetrics/internal/endpoints/endpoints.go index a4fe43f73fa..75a3ee98e87 100644 --- a/service/lookoutmetrics/internal/endpoints/endpoints.go +++ b/service/lookoutmetrics/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver LookoutMetrics endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutmetrics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutmetrics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutmetrics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutmetrics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutmetrics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutmetrics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutmetrics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutmetrics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutmetrics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutmetrics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutmetrics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/lookoutvision/api_client.go b/service/lookoutvision/api_client.go index afa99d7fda9..f8f0741813d 100644 --- a/service/lookoutvision/api_client.go +++ b/service/lookoutvision/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/lookoutvision/endpoints.go b/service/lookoutvision/endpoints.go index acdb5feba77..4be09fc318d 100644 --- a/service/lookoutvision/endpoints.go +++ b/service/lookoutvision/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/lookoutvision/generated.json b/service/lookoutvision/generated.json index c4288f27725..731ea5b6394 100644 --- a/service/lookoutvision/generated.json +++ b/service/lookoutvision/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/lookoutvision/go.mod b/service/lookoutvision/go.mod index f9831d8f7df..f57cc37dd03 100644 --- a/service/lookoutvision/go.mod +++ b/service/lookoutvision/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/lookoutvision/internal/endpoints/endpoints.go b/service/lookoutvision/internal/endpoints/endpoints.go index f3df5b518df..450417413ce 100644 --- a/service/lookoutvision/internal/endpoints/endpoints.go +++ b/service/lookoutvision/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver LookoutVision endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutvision.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutvision-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutvision.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutvision.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutvision-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutvision.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutvision.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutvision.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutvision.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "lookoutvision.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "lookoutvision.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "lookoutvision-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "lookoutvision-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "lookoutvision.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/machinelearning/api_client.go b/service/machinelearning/api_client.go index a9e29fdc72d..03eb7566c4e 100644 --- a/service/machinelearning/api_client.go +++ b/service/machinelearning/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/machinelearning/endpoints.go b/service/machinelearning/endpoints.go index dd51a6f5c2a..c23fb7236a9 100644 --- a/service/machinelearning/endpoints.go +++ b/service/machinelearning/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/machinelearning/generated.json b/service/machinelearning/generated.json index a22823af703..b05fcb6362e 100644 --- a/service/machinelearning/generated.json +++ b/service/machinelearning/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/machinelearning/go.mod b/service/machinelearning/go.mod index abdbacbe729..e4304b614c1 100644 --- a/service/machinelearning/go.mod +++ b/service/machinelearning/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/machinelearning/internal/endpoints/endpoints.go b/service/machinelearning/internal/endpoints/endpoints.go index 7dfc51e9d2d..b84fc226ebf 100644 --- a/service/machinelearning/internal/endpoints/endpoints.go +++ b/service/machinelearning/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Machine Learning endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,54 +102,141 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "machinelearning.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "machinelearning.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "machinelearning-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "machinelearning-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "machinelearning.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "machinelearning.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "machinelearning.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "machinelearning-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "machinelearning-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "machinelearning.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "machinelearning.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "machinelearning.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "machinelearning.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "machinelearning.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "machinelearning.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "machinelearning.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "machinelearning-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "machinelearning-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "machinelearning.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/macie/api_client.go b/service/macie/api_client.go index 54dd292ebc4..5cdeb42ef8b 100644 --- a/service/macie/api_client.go +++ b/service/macie/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/macie/endpoints.go b/service/macie/endpoints.go index 6d99ba2d1fd..f278e8dabcc 100644 --- a/service/macie/endpoints.go +++ b/service/macie/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/macie/generated.json b/service/macie/generated.json index ec36319474e..b86adb58217 100644 --- a/service/macie/generated.json +++ b/service/macie/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/macie/go.mod b/service/macie/go.mod index 2baea88f583..04944462e94 100644 --- a/service/macie/go.mod +++ b/service/macie/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/macie/internal/endpoints/endpoints.go b/service/macie/internal/endpoints/endpoints.go index 89d8390f0b2..782cbfc4cd1 100644 --- a/service/macie/internal/endpoints/endpoints.go +++ b/service/macie/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Macie endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,66 +102,171 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "macie.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "macie-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "macie-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "macie.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "macie.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "macie.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "macie.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "macie.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "macie.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/macie2/api_client.go b/service/macie2/api_client.go index 9a2d6cc6d70..b54c901027e 100644 --- a/service/macie2/api_client.go +++ b/service/macie2/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/macie2/endpoints.go b/service/macie2/endpoints.go index 50d92d76582..804570bcc52 100644 --- a/service/macie2/endpoints.go +++ b/service/macie2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/macie2/generated.json b/service/macie2/generated.json index 1a19233dd43..266799cd053 100644 --- a/service/macie2/generated.json +++ b/service/macie2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/macie2/go.mod b/service/macie2/go.mod index 61d4e50022a..98eab4e097e 100644 --- a/service/macie2/go.mod +++ b/service/macie2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/macie2/internal/endpoints/endpoints.go b/service/macie2/internal/endpoints/endpoints.go index fa6370ac335..b98936c4049 100644 --- a/service/macie2/internal/endpoints/endpoints.go +++ b/service/macie2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Macie2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,97 +102,258 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "macie2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "macie2-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "macie2-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "macie2-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "macie2-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "macie2.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie2.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie2.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "macie2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "macie2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "macie2.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "macie2.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "macie2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "macie2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "macie2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "macie2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "macie2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/managedblockchain/api_client.go b/service/managedblockchain/api_client.go index 6c7d4ac0ca7..2fc12c84a39 100644 --- a/service/managedblockchain/api_client.go +++ b/service/managedblockchain/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/managedblockchain/endpoints.go b/service/managedblockchain/endpoints.go index 5a303e4bb23..2246ed428e0 100644 --- a/service/managedblockchain/endpoints.go +++ b/service/managedblockchain/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/managedblockchain/generated.json b/service/managedblockchain/generated.json index 417e0bac934..1b4eab8ab65 100644 --- a/service/managedblockchain/generated.json +++ b/service/managedblockchain/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/managedblockchain/go.mod b/service/managedblockchain/go.mod index 5073869d02f..75838723fe1 100644 --- a/service/managedblockchain/go.mod +++ b/service/managedblockchain/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/managedblockchain/internal/endpoints/endpoints.go b/service/managedblockchain/internal/endpoints/endpoints.go index 9216f883677..db736e43b83 100644 --- a/service/managedblockchain/internal/endpoints/endpoints.go +++ b/service/managedblockchain/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ManagedBlockchain endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,58 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "managedblockchain.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "managedblockchain-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "managedblockchain.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "managedblockchain.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "managedblockchain-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "managedblockchain.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "managedblockchain.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "managedblockchain.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "managedblockchain.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "managedblockchain.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "managedblockchain.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "managedblockchain-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "managedblockchain-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "managedblockchain.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/marketplacecatalog/api_client.go b/service/marketplacecatalog/api_client.go index 24ce8a0d1da..f5562e10cd3 100644 --- a/service/marketplacecatalog/api_client.go +++ b/service/marketplacecatalog/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/marketplacecatalog/endpoints.go b/service/marketplacecatalog/endpoints.go index f38716d94a2..85e9a898597 100644 --- a/service/marketplacecatalog/endpoints.go +++ b/service/marketplacecatalog/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/marketplacecatalog/generated.json b/service/marketplacecatalog/generated.json index a8d56693521..13024da7224 100644 --- a/service/marketplacecatalog/generated.json +++ b/service/marketplacecatalog/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/marketplacecatalog/go.mod b/service/marketplacecatalog/go.mod index c058759e0f1..18984dc1233 100644 --- a/service/marketplacecatalog/go.mod +++ b/service/marketplacecatalog/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/marketplacecatalog/internal/endpoints/endpoints.go b/service/marketplacecatalog/internal/endpoints/endpoints.go index 8d51a4eaee9..7ad23d5b99b 100644 --- a/service/marketplacecatalog/internal/endpoints/endpoints.go +++ b/service/marketplacecatalog/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Marketplace Catalog endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "catalog.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "catalog.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "catalog.marketplace.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "catalog.marketplace.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "catalog.marketplace.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "catalog.marketplace.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "catalog.marketplace.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "catalog.marketplace.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "catalog.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "catalog.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "catalog.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/marketplacecommerceanalytics/api_client.go b/service/marketplacecommerceanalytics/api_client.go index bfc5cc940d7..98774af792e 100644 --- a/service/marketplacecommerceanalytics/api_client.go +++ b/service/marketplacecommerceanalytics/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/marketplacecommerceanalytics/endpoints.go b/service/marketplacecommerceanalytics/endpoints.go index 36499106d4e..643cc37fe86 100644 --- a/service/marketplacecommerceanalytics/endpoints.go +++ b/service/marketplacecommerceanalytics/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/marketplacecommerceanalytics/generated.json b/service/marketplacecommerceanalytics/generated.json index abaf8dab0f7..0786deb1936 100644 --- a/service/marketplacecommerceanalytics/generated.json +++ b/service/marketplacecommerceanalytics/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/marketplacecommerceanalytics/go.mod b/service/marketplacecommerceanalytics/go.mod index 20bbbaef710..634ef17adb6 100644 --- a/service/marketplacecommerceanalytics/go.mod +++ b/service/marketplacecommerceanalytics/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/marketplacecommerceanalytics/internal/endpoints/endpoints.go b/service/marketplacecommerceanalytics/internal/endpoints/endpoints.go index 8fffb4814dd..a01f3dd1922 100644 --- a/service/marketplacecommerceanalytics/internal/endpoints/endpoints.go +++ b/service/marketplacecommerceanalytics/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Marketplace Commerce Analytics endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,53 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "marketplacecommerceanalytics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "marketplacecommerceanalytics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "marketplacecommerceanalytics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "marketplacecommerceanalytics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "marketplacecommerceanalytics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "marketplacecommerceanalytics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/marketplaceentitlementservice/api_client.go b/service/marketplaceentitlementservice/api_client.go index 0e9575153b1..5de7fc43237 100644 --- a/service/marketplaceentitlementservice/api_client.go +++ b/service/marketplaceentitlementservice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/marketplaceentitlementservice/endpoints.go b/service/marketplaceentitlementservice/endpoints.go index c620de159df..46d93f06050 100644 --- a/service/marketplaceentitlementservice/endpoints.go +++ b/service/marketplaceentitlementservice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/marketplaceentitlementservice/generated.json b/service/marketplaceentitlementservice/generated.json index 15028f5089d..98ccaabd3b9 100644 --- a/service/marketplaceentitlementservice/generated.json +++ b/service/marketplaceentitlementservice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/marketplaceentitlementservice/go.mod b/service/marketplaceentitlementservice/go.mod index 435a8c5ff6f..c4616588a6b 100644 --- a/service/marketplaceentitlementservice/go.mod +++ b/service/marketplaceentitlementservice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/marketplaceentitlementservice/internal/endpoints/endpoints.go b/service/marketplaceentitlementservice/internal/endpoints/endpoints.go index 007da1b6d0d..066ea69b1ed 100644 --- a/service/marketplaceentitlementservice/internal/endpoints/endpoints.go +++ b/service/marketplaceentitlementservice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Marketplace Entitlement Service endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,56 +102,150 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "entitlement.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "aws-marketplace", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: 0, + }: { + Hostname: "entitlement.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "entitlement.marketplace.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "entitlement.marketplace.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "entitlement.marketplace.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "entitlement.marketplace.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "entitlement.marketplace.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "entitlement.marketplace.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "entitlement.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "entitlement.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "entitlement.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/marketplacemetering/api_client.go b/service/marketplacemetering/api_client.go index 29e35d8669b..61b4a2d8404 100644 --- a/service/marketplacemetering/api_client.go +++ b/service/marketplacemetering/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/marketplacemetering/endpoints.go b/service/marketplacemetering/endpoints.go index 647085eff1d..09140148217 100644 --- a/service/marketplacemetering/endpoints.go +++ b/service/marketplacemetering/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/marketplacemetering/generated.json b/service/marketplacemetering/generated.json index 565573a4f91..861a61438aa 100644 --- a/service/marketplacemetering/generated.json +++ b/service/marketplacemetering/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/marketplacemetering/go.mod b/service/marketplacemetering/go.mod index 71032823b11..007877dd388 100644 --- a/service/marketplacemetering/go.mod +++ b/service/marketplacemetering/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/marketplacemetering/internal/endpoints/endpoints.go b/service/marketplacemetering/internal/endpoints/endpoints.go index 5df4103fe5b..37021b63d04 100644 --- a/service/marketplacemetering/internal/endpoints/endpoints.go +++ b/service/marketplacemetering/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Marketplace Metering endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,85 +102,232 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "metering.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "aws-marketplace", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: 0, + }: { + Hostname: "metering.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "metering.marketplace.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "metering.marketplace.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "metering.marketplace.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "metering.marketplace.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "metering.marketplace.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "metering.marketplace.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "metering.marketplace.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "aws-marketplace", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "metering.marketplace-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, + }, + { + Variant: 0, + }: { + Hostname: "metering.marketplace.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "aws-marketplace", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/mediaconnect/api_client.go b/service/mediaconnect/api_client.go index f0d71b54cf7..f06dc9f66f3 100644 --- a/service/mediaconnect/api_client.go +++ b/service/mediaconnect/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediaconnect/endpoints.go b/service/mediaconnect/endpoints.go index 14c4325577d..ecf782a30f1 100644 --- a/service/mediaconnect/endpoints.go +++ b/service/mediaconnect/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediaconnect/generated.json b/service/mediaconnect/generated.json index 90ad1b7bcb0..219d1734c1f 100644 --- a/service/mediaconnect/generated.json +++ b/service/mediaconnect/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/mediaconnect/go.mod b/service/mediaconnect/go.mod index 36d4e0cc748..250fd2ee0b0 100644 --- a/service/mediaconnect/go.mod +++ b/service/mediaconnect/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediaconnect/internal/endpoints/endpoints.go b/service/mediaconnect/internal/endpoints/endpoints.go index 296ecb97daa..3ec4edb18b8 100644 --- a/service/mediaconnect/internal/endpoints/endpoints.go +++ b/service/mediaconnect/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaConnect endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,68 +102,183 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconnect.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconnect-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconnect.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconnect.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediaconnect.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconnect.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediaconnect.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconnect.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconnect-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconnect-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconnect.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediaconvert/api_client.go b/service/mediaconvert/api_client.go index 00f48f90dfa..e38d51a0500 100644 --- a/service/mediaconvert/api_client.go +++ b/service/mediaconvert/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/mediaconvert/endpoints.go b/service/mediaconvert/endpoints.go index 0fe377f73c3..2fe42c75dbb 100644 --- a/service/mediaconvert/endpoints.go +++ b/service/mediaconvert/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediaconvert/generated.json b/service/mediaconvert/generated.json index f5579b1a0f3..5e01b47700b 100644 --- a/service/mediaconvert/generated.json +++ b/service/mediaconvert/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediaconvert/go.mod b/service/mediaconvert/go.mod index 7628c89ef6c..1eb5b6f4f8d 100644 --- a/service/mediaconvert/go.mod +++ b/service/mediaconvert/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediaconvert/internal/endpoints/endpoints.go b/service/mediaconvert/internal/endpoints/endpoints.go index 18e7a53eb87..e4e7d697aad 100644 --- a/service/mediaconvert/internal/endpoints/endpoints.go +++ b/service/mediaconvert/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaConvert endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,73 +102,202 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconvert.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconvert.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "mediaconvert-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "mediaconvert-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "mediaconvert-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "mediaconvert-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "mediaconvert-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconvert.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconvert.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "subscribe.mediaconvert.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -131,35 +307,70 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconvert.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediaconvert.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconvert.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediaconvert.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mediaconvert.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediaconvert-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediaconvert-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediaconvert.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "mediaconvert.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/medialive/api_client.go b/service/medialive/api_client.go index 143b6e1c544..9b18ae6f183 100644 --- a/service/medialive/api_client.go +++ b/service/medialive/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/medialive/endpoints.go b/service/medialive/endpoints.go index 5b48f66c4d1..3ed1cfcbe09 100644 --- a/service/medialive/endpoints.go +++ b/service/medialive/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/medialive/generated.json b/service/medialive/generated.json index b5f920e927e..649320c9517 100644 --- a/service/medialive/generated.json +++ b/service/medialive/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/medialive/go.mod b/service/medialive/go.mod index a1f389cbbbd..f73d0b6f81b 100644 --- a/service/medialive/go.mod +++ b/service/medialive/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/medialive/internal/endpoints/endpoints.go b/service/medialive/internal/endpoints/endpoints.go index a0ac5f8dd3d..e4096510517 100644 --- a/service/medialive/internal/endpoints/endpoints.go +++ b/service/medialive/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaLive endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,87 +102,227 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "medialive.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "medialive.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "medialive-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "medialive.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "medialive-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "medialive-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "medialive-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "medialive.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "medialive.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "medialive-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "medialive.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "medialive.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "medialive.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "medialive.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "medialive.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "medialive.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "medialive.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "medialive-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "medialive-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "medialive.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediapackage/api_client.go b/service/mediapackage/api_client.go index 5c6161a10c4..b45cb0a48b8 100644 --- a/service/mediapackage/api_client.go +++ b/service/mediapackage/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediapackage/endpoints.go b/service/mediapackage/endpoints.go index 83640ec249f..a990fa36158 100644 --- a/service/mediapackage/endpoints.go +++ b/service/mediapackage/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediapackage/generated.json b/service/mediapackage/generated.json index 5c27ee70ede..3d5f0df8b2a 100644 --- a/service/mediapackage/generated.json +++ b/service/mediapackage/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediapackage/go.mod b/service/mediapackage/go.mod index 1cba0864460..87d284db3e6 100644 --- a/service/mediapackage/go.mod +++ b/service/mediapackage/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediapackage/internal/endpoints/endpoints.go b/service/mediapackage/internal/endpoints/endpoints.go index 48d651bca5c..f38fefa25b9 100644 --- a/service/mediapackage/internal/endpoints/endpoints.go +++ b/service/mediapackage/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaPackage endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,70 +102,185 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediapackage.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediapackage.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediapackagevod/api_client.go b/service/mediapackagevod/api_client.go index 811abe919c3..0969d0bb83e 100644 --- a/service/mediapackagevod/api_client.go +++ b/service/mediapackagevod/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediapackagevod/endpoints.go b/service/mediapackagevod/endpoints.go index 5d232c8e0ac..5eccbcf816a 100644 --- a/service/mediapackagevod/endpoints.go +++ b/service/mediapackagevod/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediapackagevod/generated.json b/service/mediapackagevod/generated.json index 442b95d2117..e48443efab5 100644 --- a/service/mediapackagevod/generated.json +++ b/service/mediapackagevod/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediapackagevod/go.mod b/service/mediapackagevod/go.mod index c68ee13cfd8..95343dc1223 100644 --- a/service/mediapackagevod/go.mod +++ b/service/mediapackagevod/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediapackagevod/internal/endpoints/endpoints.go b/service/mediapackagevod/internal/endpoints/endpoints.go index a5482c0bffa..c223d923fe6 100644 --- a/service/mediapackagevod/internal/endpoints/endpoints.go +++ b/service/mediapackagevod/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaPackage Vod endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage-vod.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage-vod.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage-vod.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage-vod.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage-vod.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediapackage-vod.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage-vod.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediapackage-vod.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mediapackage-vod.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediapackage-vod-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediapackage-vod.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediastore/api_client.go b/service/mediastore/api_client.go index f862120fb6a..779bb5aafb0 100644 --- a/service/mediastore/api_client.go +++ b/service/mediastore/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediastore/endpoints.go b/service/mediastore/endpoints.go index ee86f149aaa..d2f3eff7f2a 100644 --- a/service/mediastore/endpoints.go +++ b/service/mediastore/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediastore/generated.json b/service/mediastore/generated.json index 618df3401fb..c760502e489 100644 --- a/service/mediastore/generated.json +++ b/service/mediastore/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediastore/go.mod b/service/mediastore/go.mod index a36834f829e..833c9c8b858 100644 --- a/service/mediastore/go.mod +++ b/service/mediastore/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediastore/internal/endpoints/endpoints.go b/service/mediastore/internal/endpoints/endpoints.go index f4fb203ee37..ef962a5cacf 100644 --- a/service/mediastore/internal/endpoints/endpoints.go +++ b/service/mediastore/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaStore endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mediastore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediastore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediastore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediastore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediastore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mediastore.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediastore.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediastore-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediastore-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediastore.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mediastore.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediastore.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mediastore.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mediastore.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mediastore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mediastore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mediastore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mediastore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mediastore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediastoredata/api_client.go b/service/mediastoredata/api_client.go index 336ed545025..e132e232fab 100644 --- a/service/mediastoredata/api_client.go +++ b/service/mediastoredata/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediastoredata/endpoints.go b/service/mediastoredata/endpoints.go index 97c30f0268e..551eda1f7b7 100644 --- a/service/mediastoredata/endpoints.go +++ b/service/mediastoredata/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediastoredata/generated.json b/service/mediastoredata/generated.json index f5e9af55316..f3551d45ed3 100644 --- a/service/mediastoredata/generated.json +++ b/service/mediastoredata/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediastoredata/go.mod b/service/mediastoredata/go.mod index c000560d819..712f754e2c2 100644 --- a/service/mediastoredata/go.mod +++ b/service/mediastoredata/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediastoredata/internal/endpoints/endpoints.go b/service/mediastoredata/internal/endpoints/endpoints.go index 83b5502f3bf..50d03974189 100644 --- a/service/mediastoredata/internal/endpoints/endpoints.go +++ b/service/mediastoredata/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaStore Data endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "data.mediastore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.mediastore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.mediastore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "data.mediastore.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.mediastore-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.mediastore.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "data.mediastore.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.mediastore.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "data.mediastore.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "data.mediastore.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "data.mediastore.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "data.mediastore-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "data.mediastore-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "data.mediastore.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mediatailor/api_client.go b/service/mediatailor/api_client.go index 3c4419a7e1d..22846f1faae 100644 --- a/service/mediatailor/api_client.go +++ b/service/mediatailor/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mediatailor/endpoints.go b/service/mediatailor/endpoints.go index eef136742bd..5be03763bab 100644 --- a/service/mediatailor/endpoints.go +++ b/service/mediatailor/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mediatailor/generated.json b/service/mediatailor/generated.json index 51cb628007d..97d35649d8e 100644 --- a/service/mediatailor/generated.json +++ b/service/mediatailor/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mediatailor/go.mod b/service/mediatailor/go.mod index 745e21258a1..4d5746207fa 100644 --- a/service/mediatailor/go.mod +++ b/service/mediatailor/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mediatailor/internal/endpoints/endpoints.go b/service/mediatailor/internal/endpoints/endpoints.go index e6c6fe689b1..7bc1f110e24 100644 --- a/service/mediatailor/internal/endpoints/endpoints.go +++ b/service/mediatailor/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MediaTailor endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.mediatailor.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.mediatailor.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.mediatailor.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.mediatailor.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.mediatailor.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.mediatailor.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.mediatailor.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.mediatailor.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.mediatailor.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.mediatailor-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.mediatailor.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/memorydb/api_client.go b/service/memorydb/api_client.go index cfcfae1cb72..6445fc7bc52 100644 --- a/service/memorydb/api_client.go +++ b/service/memorydb/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/memorydb/endpoints.go b/service/memorydb/endpoints.go index a256af32720..0a38f821b54 100644 --- a/service/memorydb/endpoints.go +++ b/service/memorydb/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/memorydb/generated.json b/service/memorydb/generated.json index 9d3a5dd30a7..14ce5e02f9b 100644 --- a/service/memorydb/generated.json +++ b/service/memorydb/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/memorydb/go.mod b/service/memorydb/go.mod index 98a9964d99f..717a524ca19 100644 --- a/service/memorydb/go.mod +++ b/service/memorydb/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/memorydb/internal/endpoints/endpoints.go b/service/memorydb/internal/endpoints/endpoints.go index 1220d9969b1..46104871d07 100644 --- a/service/memorydb/internal/endpoints/endpoints.go +++ b/service/memorydb/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MemoryDB endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "memory-db.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "memory-db.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "memory-db-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "memory-db-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "memory-db.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "memory-db.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "memory-db.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "memory-db-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "memory-db-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "memory-db.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "memory-db.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "memory-db.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "memory-db.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "memory-db.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "memory-db.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "memory-db.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "memory-db-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "memory-db-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "memory-db.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mgn/api_client.go b/service/mgn/api_client.go index b1b7283b9c9..c6871c988bc 100644 --- a/service/mgn/api_client.go +++ b/service/mgn/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mgn/endpoints.go b/service/mgn/endpoints.go index e28d94d5ac0..0a183c30b96 100644 --- a/service/mgn/endpoints.go +++ b/service/mgn/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mgn/generated.json b/service/mgn/generated.json index aad2ee7f800..e69811b5753 100644 --- a/service/mgn/generated.json +++ b/service/mgn/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mgn/go.mod b/service/mgn/go.mod index 296c255bc32..6adaef52180 100644 --- a/service/mgn/go.mod +++ b/service/mgn/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mgn/internal/endpoints/endpoints.go b/service/mgn/internal/endpoints/endpoints.go index bc32865c8f0..d8766aaf125 100644 --- a/service/mgn/internal/endpoints/endpoints.go +++ b/service/mgn/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver mgn endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,186 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mgn.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgn.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgn-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgn-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgn.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mgn.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgn.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgn-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgn-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgn.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mgn.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mgn.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mgn.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mgn.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mgn.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgn.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgn-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgn-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgn.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/migrationhub/api_client.go b/service/migrationhub/api_client.go index 0be92dc7707..9d0185e14de 100644 --- a/service/migrationhub/api_client.go +++ b/service/migrationhub/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/migrationhub/endpoints.go b/service/migrationhub/endpoints.go index 523b7f164e9..a51c8647901 100644 --- a/service/migrationhub/endpoints.go +++ b/service/migrationhub/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/migrationhub/generated.json b/service/migrationhub/generated.json index a33ec8648a4..a104a94effe 100644 --- a/service/migrationhub/generated.json +++ b/service/migrationhub/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/migrationhub/go.mod b/service/migrationhub/go.mod index 3f4d4a8ba70..7ceca9c9c82 100644 --- a/service/migrationhub/go.mod +++ b/service/migrationhub/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/migrationhub/internal/endpoints/endpoints.go b/service/migrationhub/internal/endpoints/endpoints.go index d2534d4783f..1219c03f040 100644 --- a/service/migrationhub/internal/endpoints/endpoints.go +++ b/service/migrationhub/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Migration Hub endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mgh.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgh.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgh-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgh-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgh.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mgh.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgh.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgh-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgh-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgh.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mgh.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mgh.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mgh.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mgh.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mgh.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mgh.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mgh-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mgh-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mgh.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/migrationhubconfig/api_client.go b/service/migrationhubconfig/api_client.go index f64377c6dd8..47f088fd0e3 100644 --- a/service/migrationhubconfig/api_client.go +++ b/service/migrationhubconfig/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/migrationhubconfig/endpoints.go b/service/migrationhubconfig/endpoints.go index e0d5df49c97..9f7a07e46c0 100644 --- a/service/migrationhubconfig/endpoints.go +++ b/service/migrationhubconfig/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/migrationhubconfig/generated.json b/service/migrationhubconfig/generated.json index 59af0235b68..2f7523b3f6f 100644 --- a/service/migrationhubconfig/generated.json +++ b/service/migrationhubconfig/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/migrationhubconfig/go.mod b/service/migrationhubconfig/go.mod index e53ef677d94..ca18593654f 100644 --- a/service/migrationhubconfig/go.mod +++ b/service/migrationhubconfig/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/migrationhubconfig/internal/endpoints/endpoints.go b/service/migrationhubconfig/internal/endpoints/endpoints.go index 9bcc85bf5bb..019ca8cfb0b 100644 --- a/service/migrationhubconfig/internal/endpoints/endpoints.go +++ b/service/migrationhubconfig/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MigrationHub Config endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "migrationhub-config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "migrationhub-config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "migrationhub-config.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "migrationhub-config.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "migrationhub-config.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "migrationhub-config.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "migrationhub-config.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "migrationhub-config.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "migrationhub-config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "migrationhub-config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "migrationhub-config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mobile/api_client.go b/service/mobile/api_client.go index 846ed009004..8a0dd372050 100644 --- a/service/mobile/api_client.go +++ b/service/mobile/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mobile/endpoints.go b/service/mobile/endpoints.go index 880d821ee05..858fbd0a1a8 100644 --- a/service/mobile/endpoints.go +++ b/service/mobile/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mobile/generated.json b/service/mobile/generated.json index f6de86f03f1..13c46acd115 100644 --- a/service/mobile/generated.json +++ b/service/mobile/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mobile/go.mod b/service/mobile/go.mod index 8983ba16b6d..399d7081963 100644 --- a/service/mobile/go.mod +++ b/service/mobile/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mobile/internal/endpoints/endpoints.go b/service/mobile/internal/endpoints/endpoints.go index 5fbf4b81c0a..20dd2b2e282 100644 --- a/service/mobile/internal/endpoints/endpoints.go +++ b/service/mobile/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Mobile endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mobile.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mobile.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mobile-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mobile-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mobile.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mobile.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mobile.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mobile-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mobile-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mobile.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mobile.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mobile.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mobile.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mobile.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mobile.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mobile.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mobile-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mobile-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mobile.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mq/api_client.go b/service/mq/api_client.go index 40b4d32b000..e2353d88c13 100644 --- a/service/mq/api_client.go +++ b/service/mq/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/mq/endpoints.go b/service/mq/endpoints.go index 61a203ea956..0e3ca211a9d 100644 --- a/service/mq/endpoints.go +++ b/service/mq/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mq/generated.json b/service/mq/generated.json index e795b918034..24d31377547 100644 --- a/service/mq/generated.json +++ b/service/mq/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mq/go.mod b/service/mq/go.mod index 18ce7d93519..acfbe535fe5 100644 --- a/service/mq/go.mod +++ b/service/mq/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mq/internal/endpoints/endpoints.go b/service/mq/internal/endpoints/endpoints.go index 257784fdbed..023d17a2c15 100644 --- a/service/mq/internal/endpoints/endpoints.go +++ b/service/mq/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver mq endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,303 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mq.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mq.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mq-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mq.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mq.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mq.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mq-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mq.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mq.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mq.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mq.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mq.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mq.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mq.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mq-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mq.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "mq-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mq-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/mturk/api_client.go b/service/mturk/api_client.go index f5fc94aa587..c516f4b1dbb 100644 --- a/service/mturk/api_client.go +++ b/service/mturk/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mturk/endpoints.go b/service/mturk/endpoints.go index 510594188aa..fbb72e49dc4 100644 --- a/service/mturk/endpoints.go +++ b/service/mturk/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mturk/generated.json b/service/mturk/generated.json index d23e3faaaa3..7c5546ac421 100644 --- a/service/mturk/generated.json +++ b/service/mturk/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mturk/go.mod b/service/mturk/go.mod index 53e3f42e80a..9c1e87613ae 100644 --- a/service/mturk/go.mod +++ b/service/mturk/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mturk/internal/endpoints/endpoints.go b/service/mturk/internal/endpoints/endpoints.go index 4b84852bbac..66c56cd4e46 100644 --- a/service/mturk/internal/endpoints/endpoints.go +++ b/service/mturk/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MTurk endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,56 +102,143 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "mturk-requester.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mturk-requester-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mturk-requester.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "sandbox": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sandbox", + }: endpoints.Endpoint{ Hostname: "mturk-requester-sandbox.us-east-1.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "mturk-requester.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mturk-requester-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mturk-requester.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "mturk-requester.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mturk-requester.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "mturk-requester.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "mturk-requester.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "mturk-requester.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "mturk-requester-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "mturk-requester-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "mturk-requester.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/mwaa/api_client.go b/service/mwaa/api_client.go index 25c36edbfba..71468181e9a 100644 --- a/service/mwaa/api_client.go +++ b/service/mwaa/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/mwaa/endpoints.go b/service/mwaa/endpoints.go index d1ee46e9126..9c067b4333e 100644 --- a/service/mwaa/endpoints.go +++ b/service/mwaa/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/mwaa/generated.json b/service/mwaa/generated.json index e5dde20fa31..083a2eaa095 100644 --- a/service/mwaa/generated.json +++ b/service/mwaa/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/mwaa/go.mod b/service/mwaa/go.mod index 4ef19d08c19..3510e45afb9 100644 --- a/service/mwaa/go.mod +++ b/service/mwaa/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/mwaa/internal/endpoints/endpoints.go b/service/mwaa/internal/endpoints/endpoints.go index daa963ee0d5..f1dbb176c7b 100644 --- a/service/mwaa/internal/endpoints/endpoints.go +++ b/service/mwaa/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver MWAA endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "airflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "airflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "airflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "airflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "airflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "airflow.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "airflow.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "airflow-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "airflow-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "airflow.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "airflow.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "airflow.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "airflow.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "airflow.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "airflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "airflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "airflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "airflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "airflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/neptune/api_client.go b/service/neptune/api_client.go index e5f505ca11d..bbf66d2adea 100644 --- a/service/neptune/api_client.go +++ b/service/neptune/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -126,6 +127,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -175,6 +178,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -203,7 +208,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -245,6 +250,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/neptune/endpoints.go b/service/neptune/endpoints.go index b6476a55854..8f20a840d87 100644 --- a/service/neptune/endpoints.go +++ b/service/neptune/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/neptune/generated.json b/service/neptune/generated.json index 06aa894495e..f2057678a84 100644 --- a/service/neptune/generated.json +++ b/service/neptune/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" diff --git a/service/neptune/go.mod b/service/neptune/go.mod index 29680e8555f..13db32b4152 100644 --- a/service/neptune/go.mod +++ b/service/neptune/go.mod @@ -4,6 +4,8 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 @@ -11,4 +13,8 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/neptune/internal/endpoints/endpoints.go b/service/neptune/internal/endpoints/endpoints.go index efaeb131196..ec439584c1d 100644 --- a/service/neptune/internal/endpoints/endpoints.go +++ b/service/neptune/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Neptune endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,132 +102,380 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "rds-fips.ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "rds-fips.ca-central-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "rds.us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "rds.us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/networkfirewall/api_client.go b/service/networkfirewall/api_client.go index 9c408ebe1bb..eb5dcbcc047 100644 --- a/service/networkfirewall/api_client.go +++ b/service/networkfirewall/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/networkfirewall/endpoints.go b/service/networkfirewall/endpoints.go index d7c961672fd..917eb38e27c 100644 --- a/service/networkfirewall/endpoints.go +++ b/service/networkfirewall/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/networkfirewall/generated.json b/service/networkfirewall/generated.json index 1f0588e82a9..1703132317a 100644 --- a/service/networkfirewall/generated.json +++ b/service/networkfirewall/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/networkfirewall/go.mod b/service/networkfirewall/go.mod index 47ce268e881..db052915241 100644 --- a/service/networkfirewall/go.mod +++ b/service/networkfirewall/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/networkfirewall/internal/endpoints/endpoints.go b/service/networkfirewall/internal/endpoints/endpoints.go index f79a760616f..c7205d4493d 100644 --- a/service/networkfirewall/internal/endpoints/endpoints.go +++ b/service/networkfirewall/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Network Firewall endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,313 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "network-firewall.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "network-firewall.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "network-firewall-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "network-firewall.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "network-firewall.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "network-firewall.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "network-firewall-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "network-firewall.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "network-firewall.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "network-firewall.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "network-firewall.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "network-firewall.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "network-firewall.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "network-firewall.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "network-firewall-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "network-firewall.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "network-firewall-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "network-firewall-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/networkmanager/api_client.go b/service/networkmanager/api_client.go index 49f4332d1cf..9d2e3cd1c7c 100644 --- a/service/networkmanager/api_client.go +++ b/service/networkmanager/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/networkmanager/endpoints.go b/service/networkmanager/endpoints.go index ba55b2ff05a..995148fbcf5 100644 --- a/service/networkmanager/endpoints.go +++ b/service/networkmanager/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/networkmanager/generated.json b/service/networkmanager/generated.json index dc387c1c24f..05a14459031 100644 --- a/service/networkmanager/generated.json +++ b/service/networkmanager/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/networkmanager/go.mod b/service/networkmanager/go.mod index 85aeefd8ac4..d098d680caa 100644 --- a/service/networkmanager/go.mod +++ b/service/networkmanager/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/networkmanager/internal/endpoints/endpoints.go b/service/networkmanager/internal/endpoints/endpoints.go index 8adc41a8e6e..84502c7f89b 100644 --- a/service/networkmanager/internal/endpoints/endpoints.go +++ b/service/networkmanager/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver NetworkManager endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "networkmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "networkmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "networkmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "networkmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "networkmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "networkmanager.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "networkmanager.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "networkmanager-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "networkmanager-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "networkmanager.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "networkmanager.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "networkmanager.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "networkmanager.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "networkmanager.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "networkmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "networkmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "networkmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "networkmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "networkmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/nimble/api_client.go b/service/nimble/api_client.go index 1f9087155ea..069bedaeb0c 100644 --- a/service/nimble/api_client.go +++ b/service/nimble/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/nimble/endpoints.go b/service/nimble/endpoints.go index 3b792ee5199..464b947f87b 100644 --- a/service/nimble/endpoints.go +++ b/service/nimble/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/nimble/generated.json b/service/nimble/generated.json index aa92859ca8d..5a79e5a67a0 100644 --- a/service/nimble/generated.json +++ b/service/nimble/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/nimble/go.mod b/service/nimble/go.mod index 39b810bed65..228c8d4e8a3 100644 --- a/service/nimble/go.mod +++ b/service/nimble/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/nimble/internal/endpoints/endpoints.go b/service/nimble/internal/endpoints/endpoints.go index 5dc378146ae..206a00621eb 100644 --- a/service/nimble/internal/endpoints/endpoints.go +++ b/service/nimble/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver nimble endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,150 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "nimble.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "nimble.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "nimble-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "nimble-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "nimble.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "nimble.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "nimble.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "nimble-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "nimble-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "nimble.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "nimble.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "nimble.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "nimble.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "nimble.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "nimble.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "nimble.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "nimble-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "nimble-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "nimble.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/opensearch/api_client.go b/service/opensearch/api_client.go index a8c75749fd9..a5eed7556a0 100644 --- a/service/opensearch/api_client.go +++ b/service/opensearch/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/opensearch/endpoints.go b/service/opensearch/endpoints.go index 58e91c8ae97..4eb95d276da 100644 --- a/service/opensearch/endpoints.go +++ b/service/opensearch/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/opensearch/generated.json b/service/opensearch/generated.json index 85ea0908039..e8add69b8a2 100644 --- a/service/opensearch/generated.json +++ b/service/opensearch/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/opensearch/go.mod b/service/opensearch/go.mod index 7343bb4c0ee..94887c57080 100644 --- a/service/opensearch/go.mod +++ b/service/opensearch/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/opensearch/internal/endpoints/endpoints.go b/service/opensearch/internal/endpoints/endpoints.go index 700277e30c2..8c80766818f 100644 --- a/service/opensearch/internal/endpoints/endpoints.go +++ b/service/opensearch/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver OpenSearch endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,101 +102,242 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "es-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "es.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "es.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "es.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "es.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "es-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "es-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "es.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "es-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/opsworks/api_client.go b/service/opsworks/api_client.go index 0e9f915a77c..ad07bf5b99d 100644 --- a/service/opsworks/api_client.go +++ b/service/opsworks/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/opsworks/endpoints.go b/service/opsworks/endpoints.go index f0eff09733b..243de5da482 100644 --- a/service/opsworks/endpoints.go +++ b/service/opsworks/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/opsworks/generated.json b/service/opsworks/generated.json index 10792b619ff..8d3c3e227d9 100644 --- a/service/opsworks/generated.json +++ b/service/opsworks/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/opsworks/go.mod b/service/opsworks/go.mod index 07fba58521c..5ee5660ba76 100644 --- a/service/opsworks/go.mod +++ b/service/opsworks/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/opsworks/internal/endpoints/endpoints.go b/service/opsworks/internal/endpoints/endpoints.go index e691e2787c6..6543d0ce2f6 100644 --- a/service/opsworks/internal/endpoints/endpoints.go +++ b/service/opsworks/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver OpsWorks endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,67 +102,180 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "opsworks.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "opsworks.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/opsworkscm/api_client.go b/service/opsworkscm/api_client.go index 6a554762a9e..6df372b53ef 100644 --- a/service/opsworkscm/api_client.go +++ b/service/opsworkscm/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/opsworkscm/endpoints.go b/service/opsworkscm/endpoints.go index 1f52ec57d24..71e64ce46fd 100644 --- a/service/opsworkscm/endpoints.go +++ b/service/opsworkscm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/opsworkscm/generated.json b/service/opsworkscm/generated.json index bb85c88fc95..7b8244d96e6 100644 --- a/service/opsworkscm/generated.json +++ b/service/opsworkscm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/opsworkscm/go.mod b/service/opsworkscm/go.mod index 6d8d665f9e8..2b155f3556d 100644 --- a/service/opsworkscm/go.mod +++ b/service/opsworkscm/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/opsworkscm/internal/endpoints/endpoints.go b/service/opsworkscm/internal/endpoints/endpoints.go index 1b4a51b68db..53c4578b7b0 100644 --- a/service/opsworkscm/internal/endpoints/endpoints.go +++ b/service/opsworkscm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver OpsWorksCM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks-cm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks-cm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks-cm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks-cm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks-cm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "opsworks-cm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks-cm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "opsworks-cm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "opsworks-cm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "opsworks-cm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "opsworks-cm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/organizations/api_client.go b/service/organizations/api_client.go index 50d4cc73ef8..faa19ead2ea 100644 --- a/service/organizations/api_client.go +++ b/service/organizations/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/organizations/endpoints.go b/service/organizations/endpoints.go index d59711f1fc2..f5f0692f1ad 100644 --- a/service/organizations/endpoints.go +++ b/service/organizations/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/organizations/generated.json b/service/organizations/generated.json index 96a9fb47154..3eeef76f50a 100644 --- a/service/organizations/generated.json +++ b/service/organizations/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/organizations/go.mod b/service/organizations/go.mod index cd72e881001..c16a1721e9e 100644 --- a/service/organizations/go.mod +++ b/service/organizations/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/organizations/internal/endpoints/endpoints.go b/service/organizations/internal/endpoints/endpoints.go index 67d95f95858..999b8976cca 100644 --- a/service/organizations/internal/endpoints/endpoints.go +++ b/service/organizations/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Organizations endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,41 +102,107 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "organizations.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "organizations.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "organizations-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "organizations-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "organizations.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "organizations.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "fips-aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + Variant: endpoints.FIPSVariant, + }: { Hostname: "organizations-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, + endpoints.EndpointKey{ + Region: "fips-aws-global", + }: endpoints.Endpoint{ + Hostname: "organizations-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "organizations.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "organizations.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "organizations-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "organizations-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "organizations.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "organizations.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -99,46 +212,93 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "organizations.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "organizations.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "organizations.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "organizations.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "organizations.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "organizations.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "organizations-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "organizations-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "organizations.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: false, PartitionEndpoint: "aws-us-gov-global", Endpoints: endpoints.Endpoints{ - "aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + }: endpoints.Endpoint{ + Hostname: "organizations.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + Variant: endpoints.FIPSVariant, + }: { Hostname: "organizations.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "fips-aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-aws-us-gov-global", + }: endpoints.Endpoint{ Hostname: "organizations.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/outposts/api_client.go b/service/outposts/api_client.go index f7d008777a1..909ea730fb0 100644 --- a/service/outposts/api_client.go +++ b/service/outposts/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/outposts/endpoints.go b/service/outposts/endpoints.go index 3ceba084772..d36c768e5cf 100644 --- a/service/outposts/endpoints.go +++ b/service/outposts/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/outposts/generated.json b/service/outposts/generated.json index cb625eef57a..2b107befbb3 100644 --- a/service/outposts/generated.json +++ b/service/outposts/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/outposts/go.mod b/service/outposts/go.mod index 6acefb0a4ed..7accbf11453 100644 --- a/service/outposts/go.mod +++ b/service/outposts/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/outposts/internal/endpoints/endpoints.go b/service/outposts/internal/endpoints/endpoints.go index c8c69bd1565..3e52adc1a44 100644 --- a/service/outposts/internal/endpoints/endpoints.go +++ b/service/outposts/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Outposts endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,117 +102,293 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "outposts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "outposts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "outposts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "outposts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "outposts-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "outposts-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "outposts-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "outposts-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "outposts-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "outposts.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "outposts.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "outposts-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "outposts.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "outposts.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "outposts.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "outposts.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "outposts.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "outposts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "outposts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "outposts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "outposts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "outposts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "outposts.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "outposts.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/panorama/api_client.go b/service/panorama/api_client.go index 6522b02e881..5aa0679e3c4 100644 --- a/service/panorama/api_client.go +++ b/service/panorama/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/panorama/endpoints.go b/service/panorama/endpoints.go index d28de56650b..f1010ef6c35 100644 --- a/service/panorama/endpoints.go +++ b/service/panorama/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/panorama/generated.json b/service/panorama/generated.json index 3c8b7b4998d..c77a8eaf15f 100644 --- a/service/panorama/generated.json +++ b/service/panorama/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/panorama/go.mod b/service/panorama/go.mod index 8f44c06ab87..670249327a0 100644 --- a/service/panorama/go.mod +++ b/service/panorama/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/panorama/internal/endpoints/endpoints.go b/service/panorama/internal/endpoints/endpoints.go index 492a84dc283..0eb2c8b7ae4 100644 --- a/service/panorama/internal/endpoints/endpoints.go +++ b/service/panorama/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Panorama endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "panorama.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "panorama.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "panorama-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "panorama-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "panorama.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "panorama.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "panorama.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "panorama-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "panorama-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "panorama.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "panorama.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "panorama.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "panorama.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "panorama.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "panorama.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "panorama.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "panorama-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "panorama-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "panorama.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/personalize/api_client.go b/service/personalize/api_client.go index 6fd3dbeaea8..ca51965667e 100644 --- a/service/personalize/api_client.go +++ b/service/personalize/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/personalize/endpoints.go b/service/personalize/endpoints.go index da5ce7552af..3108f0377a8 100644 --- a/service/personalize/endpoints.go +++ b/service/personalize/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/personalize/generated.json b/service/personalize/generated.json index c4b7c898221..e5bd22382ed 100644 --- a/service/personalize/generated.json +++ b/service/personalize/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/personalize/go.mod b/service/personalize/go.mod index e82bd39a5ab..c50096a96a0 100644 --- a/service/personalize/go.mod +++ b/service/personalize/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/personalize/internal/endpoints/endpoints.go b/service/personalize/internal/endpoints/endpoints.go index f30f1b6b6fc..9bf2b7bd053 100644 --- a/service/personalize/internal/endpoints/endpoints.go +++ b/service/personalize/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Personalize endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,66 +102,173 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "personalize.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "personalize.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "personalize.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "personalize.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "personalize.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/personalizeevents/api_client.go b/service/personalizeevents/api_client.go index ada67227d4b..f9d8acc6918 100644 --- a/service/personalizeevents/api_client.go +++ b/service/personalizeevents/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/personalizeevents/endpoints.go b/service/personalizeevents/endpoints.go index a97e5ad2d40..78e610ff539 100644 --- a/service/personalizeevents/endpoints.go +++ b/service/personalizeevents/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/personalizeevents/generated.json b/service/personalizeevents/generated.json index dfc17aaf2fb..b46f67b3c82 100644 --- a/service/personalizeevents/generated.json +++ b/service/personalizeevents/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/personalizeevents/go.mod b/service/personalizeevents/go.mod index e645522e041..a4dbe4f27e8 100644 --- a/service/personalizeevents/go.mod +++ b/service/personalizeevents/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/personalizeevents/internal/endpoints/endpoints.go b/service/personalizeevents/internal/endpoints/endpoints.go index 08b014f3c73..23dc7b79aa0 100644 --- a/service/personalizeevents/internal/endpoints/endpoints.go +++ b/service/personalizeevents/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Personalize Events endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-events.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-events.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-events-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-events-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-events.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-events.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize-events.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-events.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize-events.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-events.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-events.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-events-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-events-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-events.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/personalizeruntime/api_client.go b/service/personalizeruntime/api_client.go index 6b027c0db46..ca942771f63 100644 --- a/service/personalizeruntime/api_client.go +++ b/service/personalizeruntime/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/personalizeruntime/endpoints.go b/service/personalizeruntime/endpoints.go index b072368a750..e6f001e3804 100644 --- a/service/personalizeruntime/endpoints.go +++ b/service/personalizeruntime/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/personalizeruntime/generated.json b/service/personalizeruntime/generated.json index 7e813ddf821..934e1aac6a4 100644 --- a/service/personalizeruntime/generated.json +++ b/service/personalizeruntime/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/personalizeruntime/go.mod b/service/personalizeruntime/go.mod index 8b207d0d0fb..8759f526855 100644 --- a/service/personalizeruntime/go.mod +++ b/service/personalizeruntime/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/personalizeruntime/internal/endpoints/endpoints.go b/service/personalizeruntime/internal/endpoints/endpoints.go index 9dac71df149..1eaa785a681 100644 --- a/service/personalizeruntime/internal/endpoints/endpoints.go +++ b/service/personalizeruntime/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Personalize Runtime endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-runtime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-runtime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-runtime.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-runtime.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-runtime.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize-runtime.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-runtime.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "personalize-runtime.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "personalize-runtime.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "personalize-runtime-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "personalize-runtime.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/pi/api_client.go b/service/pi/api_client.go index 18fa529f3d1..71b2302a72f 100644 --- a/service/pi/api_client.go +++ b/service/pi/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/pi/endpoints.go b/service/pi/endpoints.go index 1726089bca0..fb599cac218 100644 --- a/service/pi/endpoints.go +++ b/service/pi/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/pi/generated.json b/service/pi/generated.json index be51b5a9df5..d9aea34401d 100644 --- a/service/pi/generated.json +++ b/service/pi/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/pi/go.mod b/service/pi/go.mod index 27d3e60fc3a..bdab3e3f1e0 100644 --- a/service/pi/go.mod +++ b/service/pi/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/pi/internal/endpoints/endpoints.go b/service/pi/internal/endpoints/endpoints.go index 6b671d8728e..702a14baa97 100644 --- a/service/pi/internal/endpoints/endpoints.go +++ b/service/pi/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver PI endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,206 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "pi.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pi.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pi-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pi-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "pi.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "pi.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pi.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pi-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pi-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "pi.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "pi.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "pi.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "pi.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "pi.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "pi.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pi.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pi-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pi-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "pi.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/pinpoint/api_client.go b/service/pinpoint/api_client.go index 247c8b793b2..edb567f1ff5 100644 --- a/service/pinpoint/api_client.go +++ b/service/pinpoint/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/pinpoint/endpoints.go b/service/pinpoint/endpoints.go index 70d1b1e305d..8a1ec611042 100644 --- a/service/pinpoint/endpoints.go +++ b/service/pinpoint/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/pinpoint/generated.json b/service/pinpoint/generated.json index af6cd9a40fa..787981d370b 100644 --- a/service/pinpoint/generated.json +++ b/service/pinpoint/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/pinpoint/go.mod b/service/pinpoint/go.mod index e6a5ac83e66..75de69950cf 100644 --- a/service/pinpoint/go.mod +++ b/service/pinpoint/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/pinpoint/internal/endpoints/endpoints.go b/service/pinpoint/internal/endpoints/endpoints.go index 5cd8578160a..4b886df9c8a 100644 --- a/service/pinpoint/internal/endpoints/endpoints.go +++ b/service/pinpoint/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Pinpoint endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,107 +102,268 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "pinpoint.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "mobiletargeting", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pinpoint.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pinpoint-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: 0, + }: { + Hostname: "pinpoint.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "pinpoint-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "pinpoint-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "pinpoint.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "pinpoint.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "pinpoint.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pinpoint.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pinpoint-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "pinpoint.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "pinpoint.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "pinpoint.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "pinpoint.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "pinpoint.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "pinpoint.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "mobiletargeting", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "pinpoint.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "pinpoint-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, + }, + { + Variant: 0, + }: { + Hostname: "pinpoint.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "mobiletargeting", + }, }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "pinpoint-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "pinpoint.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "pinpoint-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, }, }, } diff --git a/service/pinpointemail/api_client.go b/service/pinpointemail/api_client.go index 8f8d1568f94..61290016c66 100644 --- a/service/pinpointemail/api_client.go +++ b/service/pinpointemail/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/pinpointemail/endpoints.go b/service/pinpointemail/endpoints.go index fb7900eed8e..8878ab50342 100644 --- a/service/pinpointemail/endpoints.go +++ b/service/pinpointemail/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/pinpointemail/generated.json b/service/pinpointemail/generated.json index 4eebf5dbcbe..96b58f84384 100644 --- a/service/pinpointemail/generated.json +++ b/service/pinpointemail/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/pinpointemail/go.mod b/service/pinpointemail/go.mod index 39002c0b463..be8786a54fa 100644 --- a/service/pinpointemail/go.mod +++ b/service/pinpointemail/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/pinpointemail/internal/endpoints/endpoints.go b/service/pinpointemail/internal/endpoints/endpoints.go index 0d847ce864a..aaa525af85d 100644 --- a/service/pinpointemail/internal/endpoints/endpoints.go +++ b/service/pinpointemail/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Pinpoint Email endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,175 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "email-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/pinpointsmsvoice/api_client.go b/service/pinpointsmsvoice/api_client.go index 4094c5a5ebf..e7eedecc993 100644 --- a/service/pinpointsmsvoice/api_client.go +++ b/service/pinpointsmsvoice/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/pinpointsmsvoice/endpoints.go b/service/pinpointsmsvoice/endpoints.go index 20fcd2d9f52..2339ea278f4 100644 --- a/service/pinpointsmsvoice/endpoints.go +++ b/service/pinpointsmsvoice/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/pinpointsmsvoice/generated.json b/service/pinpointsmsvoice/generated.json index 999aebfb56f..dd1569e119d 100644 --- a/service/pinpointsmsvoice/generated.json +++ b/service/pinpointsmsvoice/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/pinpointsmsvoice/go.mod b/service/pinpointsmsvoice/go.mod index 9de6a8e6f20..488507051b2 100644 --- a/service/pinpointsmsvoice/go.mod +++ b/service/pinpointsmsvoice/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/pinpointsmsvoice/internal/endpoints/endpoints.go b/service/pinpointsmsvoice/internal/endpoints/endpoints.go index 4e4a5a166a2..9d32e23b3ac 100644 --- a/service/pinpointsmsvoice/internal/endpoints/endpoints.go +++ b/service/pinpointsmsvoice/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Pinpoint SMS Voice endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sms-voice.pinpoint.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms-voice.pinpoint.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sms-voice.pinpoint.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms-voice.pinpoint.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sms-voice.pinpoint.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sms-voice.pinpoint.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sms-voice.pinpoint.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sms-voice.pinpoint.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sms-voice.pinpoint.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-voice.pinpoint-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms-voice.pinpoint.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/polly/api_client.go b/service/polly/api_client.go index b578b049255..47553f8b010 100644 --- a/service/polly/api_client.go +++ b/service/polly/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/polly/endpoints.go b/service/polly/endpoints.go index e855498f780..3b467962e42 100644 --- a/service/polly/endpoints.go +++ b/service/polly/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/polly/generated.json b/service/polly/generated.json index 2c365e27eae..ad682c469f3 100644 --- a/service/polly/generated.json +++ b/service/polly/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/polly/go.mod b/service/polly/go.mod index c4e62dfa371..afd1e217ea0 100644 --- a/service/polly/go.mod +++ b/service/polly/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/polly/internal/endpoints/endpoints.go b/service/polly/internal/endpoints/endpoints.go index 2e879715231..95da478836b 100644 --- a/service/polly/internal/endpoints/endpoints.go +++ b/service/polly/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Polly endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,109 +102,279 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "polly.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "polly.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "polly-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "polly.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "polly-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "polly-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "polly-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "polly-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "polly.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "polly.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "polly-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "polly.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "polly.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "polly.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "polly.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "polly.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "polly.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "polly.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "polly-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "polly.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "polly-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "polly-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/pricing/api_client.go b/service/pricing/api_client.go index af0c7baf0d8..dd9fd8f350c 100644 --- a/service/pricing/api_client.go +++ b/service/pricing/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/pricing/endpoints.go b/service/pricing/endpoints.go index 1856fc32634..5606cf23001 100644 --- a/service/pricing/endpoints.go +++ b/service/pricing/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/pricing/generated.json b/service/pricing/generated.json index b96c43dcf8c..ce729af24af 100644 --- a/service/pricing/generated.json +++ b/service/pricing/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/pricing/go.mod b/service/pricing/go.mod index f82272f77ce..2abcf795175 100644 --- a/service/pricing/go.mod +++ b/service/pricing/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/pricing/internal/endpoints/endpoints.go b/service/pricing/internal/endpoints/endpoints.go index 67a5c42f18c..c72de41e081 100644 --- a/service/pricing/internal/endpoints/endpoints.go +++ b/service/pricing/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Pricing endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,57 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.pricing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, - CredentialScope: endpoints.CredentialScope{ - Service: "pricing", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.pricing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "pricing", + }, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.pricing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "pricing", + }, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.pricing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "pricing", + }, + }, + { + Variant: 0, + }: { + Hostname: "api.pricing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + CredentialScope: endpoints.CredentialScope{ + Service: "pricing", + }, }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-south-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.pricing.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.pricing.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.pricing-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.pricing-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.pricing.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.pricing.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.pricing.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.pricing.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.pricing.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.pricing.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.pricing.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.pricing-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.pricing-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.pricing.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/proton/api_client.go b/service/proton/api_client.go index 75171e57298..662d030a03b 100644 --- a/service/proton/api_client.go +++ b/service/proton/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/proton/endpoints.go b/service/proton/endpoints.go index d4bca08ab33..a25e748aae3 100644 --- a/service/proton/endpoints.go +++ b/service/proton/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/proton/generated.json b/service/proton/generated.json index 2c8a183e3e8..74c0b0faa78 100644 --- a/service/proton/generated.json +++ b/service/proton/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/proton/go.mod b/service/proton/go.mod index 66be36eccd2..1d69e6bc87a 100644 --- a/service/proton/go.mod +++ b/service/proton/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/proton/internal/endpoints/endpoints.go b/service/proton/internal/endpoints/endpoints.go index 43e664910e2..fac7c9509cb 100644 --- a/service/proton/internal/endpoints/endpoints.go +++ b/service/proton/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Proton endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "proton.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "proton.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "proton-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "proton-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "proton.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "proton.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "proton.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "proton-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "proton-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "proton.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "proton.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "proton.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "proton.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "proton.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "proton.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "proton.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "proton-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "proton-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "proton.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/qldb/api_client.go b/service/qldb/api_client.go index 35e79024c8f..101badc839f 100644 --- a/service/qldb/api_client.go +++ b/service/qldb/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/qldb/endpoints.go b/service/qldb/endpoints.go index 2e02ea107d1..2e3cc56a53c 100644 --- a/service/qldb/endpoints.go +++ b/service/qldb/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/qldb/generated.json b/service/qldb/generated.json index 2a7eb630455..d9ac35795ab 100644 --- a/service/qldb/generated.json +++ b/service/qldb/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/qldb/go.mod b/service/qldb/go.mod index 704996c1eaf..98c8cf6d521 100644 --- a/service/qldb/go.mod +++ b/service/qldb/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/qldb/internal/endpoints/endpoints.go b/service/qldb/internal/endpoints/endpoints.go index 236a566564b..de71325c51c 100644 --- a/service/qldb/internal/endpoints/endpoints.go +++ b/service/qldb/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver QLDB endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "qldb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "qldb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "qldb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "qldb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "qldb-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "qldb-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "qldb-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "qldb.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "qldb.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "qldb-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "qldb.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "qldb.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "qldb.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "qldb.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "qldb.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "qldb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "qldb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "qldb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "qldb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "qldb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/qldbsession/api_client.go b/service/qldbsession/api_client.go index 414517b5bb3..35b2eb8007f 100644 --- a/service/qldbsession/api_client.go +++ b/service/qldbsession/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/qldbsession/endpoints.go b/service/qldbsession/endpoints.go index 53c7c150e90..25cce1ff2b4 100644 --- a/service/qldbsession/endpoints.go +++ b/service/qldbsession/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/qldbsession/generated.json b/service/qldbsession/generated.json index 83622da29d2..9c4eff11048 100644 --- a/service/qldbsession/generated.json +++ b/service/qldbsession/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/qldbsession/go.mod b/service/qldbsession/go.mod index 16a93add304..8517c54e3e3 100644 --- a/service/qldbsession/go.mod +++ b/service/qldbsession/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/qldbsession/internal/endpoints/endpoints.go b/service/qldbsession/internal/endpoints/endpoints.go index 47f0dc3656f..68ce926e1ee 100644 --- a/service/qldbsession/internal/endpoints/endpoints.go +++ b/service/qldbsession/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver QLDB Session endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,80 +102,210 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "session.qldb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "session.qldb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "session.qldb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "session.qldb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "session.qldb-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "session.qldb-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "session.qldb-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "session.qldb.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "session.qldb.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "session.qldb-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "session.qldb.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "session.qldb.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "session.qldb.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "session.qldb.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "session.qldb.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "session.qldb.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "session.qldb.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "session.qldb-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "session.qldb-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "session.qldb.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/quicksight/api_client.go b/service/quicksight/api_client.go index c6bcc2be07c..7473f123c74 100644 --- a/service/quicksight/api_client.go +++ b/service/quicksight/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/quicksight/endpoints.go b/service/quicksight/endpoints.go index 9384f8c65f2..af77890f300 100644 --- a/service/quicksight/endpoints.go +++ b/service/quicksight/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/quicksight/generated.json b/service/quicksight/generated.json index bc2beb13c61..13a1e217e21 100644 --- a/service/quicksight/generated.json +++ b/service/quicksight/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/quicksight/go.mod b/service/quicksight/go.mod index aa910fe57c8..285f7458b38 100644 --- a/service/quicksight/go.mod +++ b/service/quicksight/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/quicksight/internal/endpoints/endpoints.go b/service/quicksight/internal/endpoints/endpoints.go index 2a6fdce1afc..17b3ccbc0fb 100644 --- a/service/quicksight/internal/endpoints/endpoints.go +++ b/service/quicksight/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver QuickSight endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,72 +102,187 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "quicksight.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "quicksight.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "quicksight-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "quicksight-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "quicksight.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "api": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "api", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "quicksight.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "quicksight.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "quicksight-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "quicksight-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "quicksight.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "quicksight.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "quicksight.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "quicksight.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "quicksight.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "quicksight.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "quicksight.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "quicksight-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "quicksight-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "quicksight.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "api": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "api", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/ram/api_client.go b/service/ram/api_client.go index f797afc088d..6780f0ecef7 100644 --- a/service/ram/api_client.go +++ b/service/ram/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ram/endpoints.go b/service/ram/endpoints.go index 6bc27d43863..5e11708288e 100644 --- a/service/ram/endpoints.go +++ b/service/ram/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ram/generated.json b/service/ram/generated.json index ac26d462937..d8efeefe1b7 100644 --- a/service/ram/generated.json +++ b/service/ram/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ram/go.mod b/service/ram/go.mod index e861fd179f8..13cad3a00aa 100644 --- a/service/ram/go.mod +++ b/service/ram/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ram/internal/endpoints/endpoints.go b/service/ram/internal/endpoints/endpoints.go index 9cf38c418c5..a175fd825ec 100644 --- a/service/ram/internal/endpoints/endpoints.go +++ b/service/ram/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver RAM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,301 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ram.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ram.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ram-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ram.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "ram-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ram-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ram-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ram-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ram-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ram.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ram.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ram-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ram.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ram.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ram.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ram.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ram.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ram.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ram.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ram-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ram-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ram.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ram.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ram.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/rds/api_client.go b/service/rds/api_client.go index ae5db01b70a..5c9dcbe0c9e 100644 --- a/service/rds/api_client.go +++ b/service/rds/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -127,6 +128,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -176,6 +179,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -204,7 +209,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -246,6 +251,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/rds/endpoints.go b/service/rds/endpoints.go index 4ae4d0620d3..aea54a92a46 100644 --- a/service/rds/endpoints.go +++ b/service/rds/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/rds/generated.json b/service/rds/generated.json index 7a7f170a2f7..d42321e8b92 100644 --- a/service/rds/generated.json +++ b/service/rds/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" diff --git a/service/rds/go.mod b/service/rds/go.mod index 13208dd3bd3..7da41c9c0e9 100644 --- a/service/rds/go.mod +++ b/service/rds/go.mod @@ -4,6 +4,8 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 @@ -11,4 +13,8 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/rds/internal/endpoints/endpoints.go b/service/rds/internal/endpoints/endpoints.go index 1e2bb87abb1..2ce8674b43a 100644 --- a/service/rds/internal/endpoints/endpoints.go +++ b/service/rds/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver RDS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,132 +102,380 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "rds-fips.ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "rds-fips.ca-central-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-east-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-1", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds-fips.us-west-2", + }: endpoints.Endpoint{ + Hostname: "rds-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.ca-central-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-east-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "rds-fips.us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rds.us-west-2", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rds-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "rds.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "rds.us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "rds.us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rds.us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "rds.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/rdsdata/api_client.go b/service/rdsdata/api_client.go index 891e673e8a3..fa9176cc473 100644 --- a/service/rdsdata/api_client.go +++ b/service/rdsdata/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/rdsdata/endpoints.go b/service/rdsdata/endpoints.go index 9d9318aaa6e..bb11e429633 100644 --- a/service/rdsdata/endpoints.go +++ b/service/rdsdata/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/rdsdata/generated.json b/service/rdsdata/generated.json index b4965a6fcc0..d46c692125b 100644 --- a/service/rdsdata/generated.json +++ b/service/rdsdata/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/rdsdata/go.mod b/service/rdsdata/go.mod index f514cc83148..cea38616c49 100644 --- a/service/rdsdata/go.mod +++ b/service/rdsdata/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/rdsdata/internal/endpoints/endpoints.go b/service/rdsdata/internal/endpoints/endpoints.go index a0b7798e066..be4d3e57b83 100644 --- a/service/rdsdata/internal/endpoints/endpoints.go +++ b/service/rdsdata/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver RDS Data endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "rds-data.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds-data.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-data-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-data-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds-data.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "rds-data.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds-data.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-data-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-data-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds-data.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "rds-data.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds-data.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "rds-data.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rds-data.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "rds-data.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rds-data.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rds-data-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rds-data-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rds-data.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/redshift/api_client.go b/service/redshift/api_client.go index 1b007132d2e..e23bf0b8925 100644 --- a/service/redshift/api_client.go +++ b/service/redshift/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/redshift/endpoints.go b/service/redshift/endpoints.go index 62ff99a87cc..e131f0074c8 100644 --- a/service/redshift/endpoints.go +++ b/service/redshift/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/redshift/generated.json b/service/redshift/generated.json index f25d7ff70e6..7b2ca9168db 100644 --- a/service/redshift/generated.json +++ b/service/redshift/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/redshift/go.mod b/service/redshift/go.mod index 9fc893cbdbe..9639c3b6bdb 100644 --- a/service/redshift/go.mod +++ b/service/redshift/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/redshift/internal/endpoints/endpoints.go b/service/redshift/internal/endpoints/endpoints.go index 37d537d60b6..ac21a8c7ff8 100644 --- a/service/redshift/internal/endpoints/endpoints.go +++ b/service/redshift/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Redshift endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,125 +102,309 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "redshift.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "redshift-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "redshift-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "redshift-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "redshift-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "redshift-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "redshift.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "redshift.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "redshift.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "redshift.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "redshift.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "redshift.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "redshift.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "redshift.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/redshiftdata/api_client.go b/service/redshiftdata/api_client.go index e576713cb85..1a790ae0bc2 100644 --- a/service/redshiftdata/api_client.go +++ b/service/redshiftdata/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/redshiftdata/endpoints.go b/service/redshiftdata/endpoints.go index d2692499bd6..2896a32d5aa 100644 --- a/service/redshiftdata/endpoints.go +++ b/service/redshiftdata/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/redshiftdata/generated.json b/service/redshiftdata/generated.json index 8f24eb2d0e3..950f5510f35 100644 --- a/service/redshiftdata/generated.json +++ b/service/redshiftdata/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/redshiftdata/go.mod b/service/redshiftdata/go.mod index f22aa686e01..37e4e76710a 100644 --- a/service/redshiftdata/go.mod +++ b/service/redshiftdata/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/redshiftdata/internal/endpoints/endpoints.go b/service/redshiftdata/internal/endpoints/endpoints.go index 17c3d010231..0f4c4e235d1 100644 --- a/service/redshiftdata/internal/endpoints/endpoints.go +++ b/service/redshiftdata/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Redshift Data endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "redshift-data.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift-data.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-data-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-data-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift-data.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "redshift-data.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift-data.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-data-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-data-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift-data.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "redshift-data.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "redshift-data.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "redshift-data.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "redshift-data.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "redshift-data.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "redshift-data.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "redshift-data-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "redshift-data-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "redshift-data.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/rekognition/api_client.go b/service/rekognition/api_client.go index ff1c40e5cf9..0b5427f91f5 100644 --- a/service/rekognition/api_client.go +++ b/service/rekognition/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/rekognition/endpoints.go b/service/rekognition/endpoints.go index 4dc73fbe215..d708d57e16a 100644 --- a/service/rekognition/endpoints.go +++ b/service/rekognition/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/rekognition/generated.json b/service/rekognition/generated.json index 0e08c71ed95..bad8c221d7b 100644 --- a/service/rekognition/generated.json +++ b/service/rekognition/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/rekognition/go.mod b/service/rekognition/go.mod index e40d3c054dc..928e6b7cbb4 100644 --- a/service/rekognition/go.mod +++ b/service/rekognition/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/rekognition/internal/endpoints/endpoints.go b/service/rekognition/internal/endpoints/endpoints.go index 6eb3373675c..b1cbae83651 100644 --- a/service/rekognition/internal/endpoints/endpoints.go +++ b/service/rekognition/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Rekognition endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,106 +102,343 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "rekognition.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rekognition.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rekognition-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rekognition.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "rekognition-fips.ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "rekognition-fips.ca-central-1", + }: endpoints.Endpoint{ Hostname: "rekognition-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "rekognition-fips.us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rekognition-fips.us-east-1", + }: endpoints.Endpoint{ Hostname: "rekognition-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "rekognition-fips.us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rekognition-fips.us-east-2", + }: endpoints.Endpoint{ Hostname: "rekognition-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "rekognition-fips.us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rekognition-fips.us-west-1", + }: endpoints.Endpoint{ Hostname: "rekognition-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "rekognition-fips.us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rekognition-fips.us-west-2", + }: endpoints.Endpoint{ Hostname: "rekognition-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.ca-central-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-east-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-east-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "rekognition.us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-west-2", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "rekognition.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rekognition.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rekognition-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rekognition.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "rekognition.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rekognition.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "rekognition.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "rekognition.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "rekognition.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "rekognition.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "rekognition-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "rekognition-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "rekognition.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "rekognition-fips.us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "rekognition-fips.us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "rekognition-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-gov-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "rekognition.us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "rekognition-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/resourcegroups/api_client.go b/service/resourcegroups/api_client.go index 70562694fdc..c81cfda1063 100644 --- a/service/resourcegroups/api_client.go +++ b/service/resourcegroups/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/resourcegroups/endpoints.go b/service/resourcegroups/endpoints.go index 8e0f751fc12..262bcce6a42 100644 --- a/service/resourcegroups/endpoints.go +++ b/service/resourcegroups/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/resourcegroups/generated.json b/service/resourcegroups/generated.json index f87981ec651..70f53c08caa 100644 --- a/service/resourcegroups/generated.json +++ b/service/resourcegroups/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/resourcegroups/go.mod b/service/resourcegroups/go.mod index 25861595710..da4d8623e73 100644 --- a/service/resourcegroups/go.mod +++ b/service/resourcegroups/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/resourcegroups/internal/endpoints/endpoints.go b/service/resourcegroups/internal/endpoints/endpoints.go index 00b99bab288..c9ea41c8c5d 100644 --- a/service/resourcegroups/internal/endpoints/endpoints.go +++ b/service/resourcegroups/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Resource Groups endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "resource-groups.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "resource-groups.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "resource-groups-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "resource-groups.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "resource-groups-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "resource-groups-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "resource-groups-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "resource-groups-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "resource-groups.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "resource-groups.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "resource-groups-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "resource-groups.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "resource-groups.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "resource-groups.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "resource-groups.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "resource-groups.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "resource-groups.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "resource-groups.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "resource-groups-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "resource-groups.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "resource-groups.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "resource-groups.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "resource-groups.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/resourcegroupstaggingapi/api_client.go b/service/resourcegroupstaggingapi/api_client.go index 0a0a8b4c3ed..a9281febc30 100644 --- a/service/resourcegroupstaggingapi/api_client.go +++ b/service/resourcegroupstaggingapi/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/resourcegroupstaggingapi/endpoints.go b/service/resourcegroupstaggingapi/endpoints.go index e9995e62468..d2327c7bbce 100644 --- a/service/resourcegroupstaggingapi/endpoints.go +++ b/service/resourcegroupstaggingapi/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/resourcegroupstaggingapi/generated.json b/service/resourcegroupstaggingapi/generated.json index 8767a920882..8e9fcea5bb7 100644 --- a/service/resourcegroupstaggingapi/generated.json +++ b/service/resourcegroupstaggingapi/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/resourcegroupstaggingapi/go.mod b/service/resourcegroupstaggingapi/go.mod index 75a2b49caa8..005e5660cc5 100644 --- a/service/resourcegroupstaggingapi/go.mod +++ b/service/resourcegroupstaggingapi/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/resourcegroupstaggingapi/internal/endpoints/endpoints.go b/service/resourcegroupstaggingapi/internal/endpoints/endpoints.go index 712a4ca9e1b..d5e1d48c273 100644 --- a/service/resourcegroupstaggingapi/internal/endpoints/endpoints.go +++ b/service/resourcegroupstaggingapi/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Resource Groups Tagging API endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,86 +102,221 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "tagging.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "tagging.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "tagging-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "tagging-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "tagging.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "tagging.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "tagging.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "tagging-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "tagging-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "tagging.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "tagging.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "tagging.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "tagging.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "tagging.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "tagging.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "tagging.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "tagging-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "tagging-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "tagging.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/robomaker/api_client.go b/service/robomaker/api_client.go index 71b188902c6..f1abefaa276 100644 --- a/service/robomaker/api_client.go +++ b/service/robomaker/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/robomaker/endpoints.go b/service/robomaker/endpoints.go index a798b233670..19b08d660bd 100644 --- a/service/robomaker/endpoints.go +++ b/service/robomaker/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/robomaker/generated.json b/service/robomaker/generated.json index 8878f132153..a905a9a4626 100644 --- a/service/robomaker/generated.json +++ b/service/robomaker/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/robomaker/go.mod b/service/robomaker/go.mod index dda0cada829..00fa6885770 100644 --- a/service/robomaker/go.mod +++ b/service/robomaker/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/robomaker/internal/endpoints/endpoints.go b/service/robomaker/internal/endpoints/endpoints.go index 75994981c0e..bd5ab3b73b8 100644 --- a/service/robomaker/internal/endpoints/endpoints.go +++ b/service/robomaker/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver RoboMaker endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "robomaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "robomaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "robomaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "robomaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "robomaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "robomaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "robomaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "robomaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "robomaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "robomaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "robomaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "robomaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "robomaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "robomaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "robomaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "robomaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "robomaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "robomaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "robomaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/route53/api_client.go b/service/route53/api_client.go index 002a39902e7..ec1c99854d1 100644 --- a/service/route53/api_client.go +++ b/service/route53/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" route53cust "github.com/aws/aws-sdk-go-v2/service/route53/internal/customizations" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -126,6 +127,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -175,6 +178,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -203,7 +208,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -245,6 +250,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/route53/endpoints.go b/service/route53/endpoints.go index b8966449b53..b7651091019 100644 --- a/service/route53/endpoints.go +++ b/service/route53/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53/generated.json b/service/route53/generated.json index 8defb0fffcc..838e106c9b0 100644 --- a/service/route53/generated.json +++ b/service/route53/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/route53/go.mod b/service/route53/go.mod index 2307bd383c0..64f3c2f88af 100644 --- a/service/route53/go.mod +++ b/service/route53/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53/internal/endpoints/endpoints.go b/service/route53/internal/endpoints/endpoints.go index 9c82fc9a158..24d3480a61b 100644 --- a/service/route53/internal/endpoints/endpoints.go +++ b/service/route53/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route 53 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,41 +102,107 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "route53.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "fips-aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + Variant: endpoints.FIPSVariant, + }: { Hostname: "route53-fips.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, + endpoints.EndpointKey{ + Region: "fips-aws-global", + }: endpoints.Endpoint{ + Hostname: "route53-fips.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: false, PartitionEndpoint: "aws-cn-global", Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "route53.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -99,16 +212,22 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: false, PartitionEndpoint: "aws-iso-global", Endpoints: endpoints.Endpoints{ - "aws-iso-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-global", + }: endpoints.Endpoint{ Hostname: "route53.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", @@ -118,16 +237,22 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: false, PartitionEndpoint: "aws-iso-b-global", Endpoints: endpoints.Endpoints{ - "aws-iso-b-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-b-global", + }: endpoints.Endpoint{ Hostname: "route53.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", @@ -137,26 +262,65 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: false, PartitionEndpoint: "aws-us-gov-global", Endpoints: endpoints.Endpoints{ - "aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + }: endpoints.Endpoint{ + Hostname: "route53.us-gov.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + Variant: endpoints.FIPSVariant, + }: { Hostname: "route53.us-gov.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "fips-aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-aws-us-gov-global", + }: endpoints.Endpoint{ Hostname: "route53.us-gov.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/route53domains/api_client.go b/service/route53domains/api_client.go index 2f7f51e119c..a15474db72d 100644 --- a/service/route53domains/api_client.go +++ b/service/route53domains/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/route53domains/endpoints.go b/service/route53domains/endpoints.go index bf0db236204..6b6af99f506 100644 --- a/service/route53domains/endpoints.go +++ b/service/route53domains/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53domains/generated.json b/service/route53domains/generated.json index fbe805ab88d..d47541a0ba9 100644 --- a/service/route53domains/generated.json +++ b/service/route53domains/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/route53domains/go.mod b/service/route53domains/go.mod index 2c1eab920d8..4e439123719 100644 --- a/service/route53domains/go.mod +++ b/service/route53domains/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53domains/internal/endpoints/endpoints.go b/service/route53domains/internal/endpoints/endpoints.go index 3b1cf0a397e..0e0d31e77e7 100644 --- a/service/route53domains/internal/endpoints/endpoints.go +++ b/service/route53domains/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route 53 Domains endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,53 +102,138 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53domains.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53domains.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53domains-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53domains-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53domains.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53domains.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53domains.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53domains-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53domains-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53domains.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53domains.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53domains.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53domains.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53domains.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53domains.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53domains.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53domains-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53domains-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53domains.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/route53recoverycluster/api_client.go b/service/route53recoverycluster/api_client.go index 9ddeab06856..26d25df04af 100644 --- a/service/route53recoverycluster/api_client.go +++ b/service/route53recoverycluster/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/route53recoverycluster/endpoints.go b/service/route53recoverycluster/endpoints.go index ef03ae90e61..c2ccaeadb44 100644 --- a/service/route53recoverycluster/endpoints.go +++ b/service/route53recoverycluster/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53recoverycluster/generated.json b/service/route53recoverycluster/generated.json index d930b3741f9..95c2886d7d9 100644 --- a/service/route53recoverycluster/generated.json +++ b/service/route53recoverycluster/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/route53recoverycluster/go.mod b/service/route53recoverycluster/go.mod index 3712a121464..fbf87899542 100644 --- a/service/route53recoverycluster/go.mod +++ b/service/route53recoverycluster/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53recoverycluster/internal/endpoints/endpoints.go b/service/route53recoverycluster/internal/endpoints/endpoints.go index 100031ef9a7..44f7681ec7c 100644 --- a/service/route53recoverycluster/internal/endpoints/endpoints.go +++ b/service/route53recoverycluster/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route53 Recovery Cluster endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-cluster.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-cluster.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-cluster.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-cluster.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-cluster.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-cluster.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-cluster.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-cluster.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-cluster.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-cluster-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-cluster.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/route53recoverycontrolconfig/api_client.go b/service/route53recoverycontrolconfig/api_client.go index 68886d49fb0..cc732c35a39 100644 --- a/service/route53recoverycontrolconfig/api_client.go +++ b/service/route53recoverycontrolconfig/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/route53recoverycontrolconfig/endpoints.go b/service/route53recoverycontrolconfig/endpoints.go index d7a68b1a250..81191559b23 100644 --- a/service/route53recoverycontrolconfig/endpoints.go +++ b/service/route53recoverycontrolconfig/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53recoverycontrolconfig/generated.json b/service/route53recoverycontrolconfig/generated.json index 7ea74bb00b1..7e77ca561a6 100644 --- a/service/route53recoverycontrolconfig/generated.json +++ b/service/route53recoverycontrolconfig/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/route53recoverycontrolconfig/go.mod b/service/route53recoverycontrolconfig/go.mod index f1e3f80cf3d..e5cb3536b72 100644 --- a/service/route53recoverycontrolconfig/go.mod +++ b/service/route53recoverycontrolconfig/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53recoverycontrolconfig/internal/endpoints/endpoints.go b/service/route53recoverycontrolconfig/internal/endpoints/endpoints.go index 887ee4c217d..0b1a7a31e4f 100644 --- a/service/route53recoverycontrolconfig/internal/endpoints/endpoints.go +++ b/service/route53recoverycontrolconfig/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route53 Recovery Control Config endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,15 +102,42 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-control-config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-control-config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "route53-recovery-control-config.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", @@ -73,40 +147,98 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-control-config.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-control-config.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-control-config.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-control-config.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-control-config.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-control-config.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-control-config.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-control-config-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-control-config.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/route53recoveryreadiness/api_client.go b/service/route53recoveryreadiness/api_client.go index f38fac1bd65..45309ae3a20 100644 --- a/service/route53recoveryreadiness/api_client.go +++ b/service/route53recoveryreadiness/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/route53recoveryreadiness/endpoints.go b/service/route53recoveryreadiness/endpoints.go index b6a92651c1a..62cde8c84b0 100644 --- a/service/route53recoveryreadiness/endpoints.go +++ b/service/route53recoveryreadiness/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53recoveryreadiness/generated.json b/service/route53recoveryreadiness/generated.json index 2cf773160f7..0c7ace4852a 100644 --- a/service/route53recoveryreadiness/generated.json +++ b/service/route53recoveryreadiness/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/route53recoveryreadiness/go.mod b/service/route53recoveryreadiness/go.mod index 6221845be67..34463b256c4 100644 --- a/service/route53recoveryreadiness/go.mod +++ b/service/route53recoveryreadiness/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53recoveryreadiness/internal/endpoints/endpoints.go b/service/route53recoveryreadiness/internal/endpoints/endpoints.go index 845d073ae7c..ffeaad1ddaa 100644 --- a/service/route53recoveryreadiness/internal/endpoints/endpoints.go +++ b/service/route53recoveryreadiness/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route53 Recovery Readiness endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-readiness.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-readiness.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-readiness.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-readiness.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-readiness.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-readiness.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-readiness.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53-recovery-readiness.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53-recovery-readiness.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53-recovery-readiness-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53-recovery-readiness.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/route53resolver/api_client.go b/service/route53resolver/api_client.go index fa554df62ee..385797084b3 100644 --- a/service/route53resolver/api_client.go +++ b/service/route53resolver/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/route53resolver/endpoints.go b/service/route53resolver/endpoints.go index 1ceccc16080..52302107d72 100644 --- a/service/route53resolver/endpoints.go +++ b/service/route53resolver/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/route53resolver/generated.json b/service/route53resolver/generated.json index 4504eb3f364..defb1d5d05a 100644 --- a/service/route53resolver/generated.json +++ b/service/route53resolver/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/route53resolver/go.mod b/service/route53resolver/go.mod index af007d9d96b..5f7ebcb933f 100644 --- a/service/route53resolver/go.mod +++ b/service/route53resolver/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/route53resolver/internal/endpoints/endpoints.go b/service/route53resolver/internal/endpoints/endpoints.go index e7f67290cc3..950349a0ed1 100644 --- a/service/route53resolver/internal/endpoints/endpoints.go +++ b/service/route53resolver/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Route53Resolver endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,86 +102,221 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "route53resolver.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53resolver.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53resolver-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53resolver-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53resolver.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "route53resolver.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53resolver.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53resolver-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53resolver-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53resolver.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "route53resolver.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53resolver.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "route53resolver.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "route53resolver.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "route53resolver.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "route53resolver.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "route53resolver-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "route53resolver-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "route53resolver.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/s3/api_client.go b/service/s3/api_client.go index 49d74516b55..622da1e5ca1 100644 --- a/service/s3/api_client.go +++ b/service/s3/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" acceptencodingcust "github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" "github.com/aws/aws-sdk-go-v2/service/internal/s3shared" @@ -110,7 +111,11 @@ type Options struct { // DNS compatible to work with accelerate. UseAccelerate bool - // Allows you to enable Dualstack endpoint support for the service. + // Allows you to enable dual-stack endpoint support for the service. + // + // Deprecated: Set dual-stack by setting UseDualStackEndpoint on + // EndpointResolverOptions. When EndpointResolverOptions' UseDualStackEndpoint + // field is set it overrides this field value. UseDualstack bool // Allows you to enable the client to use path-style addressing, i.e., @@ -161,6 +166,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + resolveCredentialProvider(&options) for _, fn := range stackFns { @@ -213,6 +220,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) resolveUseARNRegion(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -241,7 +250,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -299,6 +308,36 @@ func resolveUseARNRegion(cfg aws.Config, o *Options) error { return nil } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func resolveCredentialProvider(o *Options) { if o.Credentials == nil { return diff --git a/service/s3/api_op_AbortMultipartUpload.go b/service/s3/api_op_AbortMultipartUpload.go index cdbb30d0900..25b0b762bf5 100644 --- a/service/s3/api_op_AbortMultipartUpload.go +++ b/service/s3/api_op_AbortMultipartUpload.go @@ -225,7 +225,6 @@ func addAbortMultipartUploadUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_CompleteMultipartUpload.go b/service/s3/api_op_CompleteMultipartUpload.go index dbee35ec5d1..5fc95403acf 100644 --- a/service/s3/api_op_CompleteMultipartUpload.go +++ b/service/s3/api_op_CompleteMultipartUpload.go @@ -338,7 +338,6 @@ func addCompleteMultipartUploadUpdateEndpoint(stack *middleware.Stack, options O TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_CopyObject.go b/service/s3/api_op_CopyObject.go index e84472d8931..627c11a63bd 100644 --- a/service/s3/api_op_CopyObject.go +++ b/service/s3/api_op_CopyObject.go @@ -547,7 +547,6 @@ func addCopyObjectUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_CreateBucket.go b/service/s3/api_op_CreateBucket.go index 5c8596da7a4..38ea2c5f018 100644 --- a/service/s3/api_op_CreateBucket.go +++ b/service/s3/api_op_CreateBucket.go @@ -281,7 +281,6 @@ func addCreateBucketUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_CreateMultipartUpload.go b/service/s3/api_op_CreateMultipartUpload.go index ecfa09c9e19..9e3f7ed85b3 100644 --- a/service/s3/api_op_CreateMultipartUpload.go +++ b/service/s3/api_op_CreateMultipartUpload.go @@ -588,7 +588,6 @@ func addCreateMultipartUploadUpdateEndpoint(stack *middleware.Stack, options Opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucket.go b/service/s3/api_op_DeleteBucket.go index 3d43d1ab780..bcbfc3590a7 100644 --- a/service/s3/api_op_DeleteBucket.go +++ b/service/s3/api_op_DeleteBucket.go @@ -162,7 +162,6 @@ func addDeleteBucketUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketAnalyticsConfiguration.go b/service/s3/api_op_DeleteBucketAnalyticsConfiguration.go index e5603aebc78..6f7ab3ff799 100644 --- a/service/s3/api_op_DeleteBucketAnalyticsConfiguration.go +++ b/service/s3/api_op_DeleteBucketAnalyticsConfiguration.go @@ -182,7 +182,6 @@ func addDeleteBucketAnalyticsConfigurationUpdateEndpoint(stack *middleware.Stack TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketCors.go b/service/s3/api_op_DeleteBucketCors.go index 12651222715..07fe6302ffa 100644 --- a/service/s3/api_op_DeleteBucketCors.go +++ b/service/s3/api_op_DeleteBucketCors.go @@ -165,7 +165,6 @@ func addDeleteBucketCorsUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketEncryption.go b/service/s3/api_op_DeleteBucketEncryption.go index 0ec41d860f6..79f70860b74 100644 --- a/service/s3/api_op_DeleteBucketEncryption.go +++ b/service/s3/api_op_DeleteBucketEncryption.go @@ -173,7 +173,6 @@ func addDeleteBucketEncryptionUpdateEndpoint(stack *middleware.Stack, options Op TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketIntelligentTieringConfiguration.go b/service/s3/api_op_DeleteBucketIntelligentTieringConfiguration.go index 4e6d6e374ec..7a289f64585 100644 --- a/service/s3/api_op_DeleteBucketIntelligentTieringConfiguration.go +++ b/service/s3/api_op_DeleteBucketIntelligentTieringConfiguration.go @@ -182,7 +182,6 @@ func addDeleteBucketIntelligentTieringConfigurationUpdateEndpoint(stack *middlew TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketInventoryConfiguration.go b/service/s3/api_op_DeleteBucketInventoryConfiguration.go index 2fdcba3450d..9d0e6a8b861 100644 --- a/service/s3/api_op_DeleteBucketInventoryConfiguration.go +++ b/service/s3/api_op_DeleteBucketInventoryConfiguration.go @@ -181,7 +181,6 @@ func addDeleteBucketInventoryConfigurationUpdateEndpoint(stack *middleware.Stack TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketLifecycle.go b/service/s3/api_op_DeleteBucketLifecycle.go index c1505017fbf..f1c59da4528 100644 --- a/service/s3/api_op_DeleteBucketLifecycle.go +++ b/service/s3/api_op_DeleteBucketLifecycle.go @@ -171,7 +171,6 @@ func addDeleteBucketLifecycleUpdateEndpoint(stack *middleware.Stack, options Opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketMetricsConfiguration.go b/service/s3/api_op_DeleteBucketMetricsConfiguration.go index a6ed77d2e48..c9d7e8c782b 100644 --- a/service/s3/api_op_DeleteBucketMetricsConfiguration.go +++ b/service/s3/api_op_DeleteBucketMetricsConfiguration.go @@ -187,7 +187,6 @@ func addDeleteBucketMetricsConfigurationUpdateEndpoint(stack *middleware.Stack, TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketOwnershipControls.go b/service/s3/api_op_DeleteBucketOwnershipControls.go index 82211a1f4ec..2f3dc331992 100644 --- a/service/s3/api_op_DeleteBucketOwnershipControls.go +++ b/service/s3/api_op_DeleteBucketOwnershipControls.go @@ -164,7 +164,6 @@ func addDeleteBucketOwnershipControlsUpdateEndpoint(stack *middleware.Stack, opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketPolicy.go b/service/s3/api_op_DeleteBucketPolicy.go index c76b8ac428f..815b5baabdc 100644 --- a/service/s3/api_op_DeleteBucketPolicy.go +++ b/service/s3/api_op_DeleteBucketPolicy.go @@ -174,7 +174,6 @@ func addDeleteBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketReplication.go b/service/s3/api_op_DeleteBucketReplication.go index 214b55c0cb8..3489765b58b 100644 --- a/service/s3/api_op_DeleteBucketReplication.go +++ b/service/s3/api_op_DeleteBucketReplication.go @@ -172,7 +172,6 @@ func addDeleteBucketReplicationUpdateEndpoint(stack *middleware.Stack, options O TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketTagging.go b/service/s3/api_op_DeleteBucketTagging.go index b06905471ec..e05f3d44d9a 100644 --- a/service/s3/api_op_DeleteBucketTagging.go +++ b/service/s3/api_op_DeleteBucketTagging.go @@ -163,7 +163,6 @@ func addDeleteBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteBucketWebsite.go b/service/s3/api_op_DeleteBucketWebsite.go index 200eec07a80..a1d22e9e948 100644 --- a/service/s3/api_op_DeleteBucketWebsite.go +++ b/service/s3/api_op_DeleteBucketWebsite.go @@ -172,7 +172,6 @@ func addDeleteBucketWebsiteUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteObject.go b/service/s3/api_op_DeleteObject.go index 85ad072fadb..54468e90a75 100644 --- a/service/s3/api_op_DeleteObject.go +++ b/service/s3/api_op_DeleteObject.go @@ -232,7 +232,6 @@ func addDeleteObjectUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteObjectTagging.go b/service/s3/api_op_DeleteObjectTagging.go index cf7a5437e75..81640f66fc0 100644 --- a/service/s3/api_op_DeleteObjectTagging.go +++ b/service/s3/api_op_DeleteObjectTagging.go @@ -195,7 +195,6 @@ func addDeleteObjectTaggingUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeleteObjects.go b/service/s3/api_op_DeleteObjects.go index 94de978afd0..7e439da48c9 100644 --- a/service/s3/api_op_DeleteObjects.go +++ b/service/s3/api_op_DeleteObjects.go @@ -193,6 +193,9 @@ func (c *Client) addOperationDeleteObjectsMiddlewares(stack *middleware.Stack, o if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpDeleteObjectsValidationMiddleware(stack); err != nil { return err } @@ -217,9 +220,6 @@ func (c *Client) addOperationDeleteObjectsMiddlewares(stack *middleware.Stack, o if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -253,7 +253,6 @@ func addDeleteObjectsUpdateEndpoint(stack *middleware.Stack, options Options) er TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_DeletePublicAccessBlock.go b/service/s3/api_op_DeletePublicAccessBlock.go index 020d364f6f0..04df4643e42 100644 --- a/service/s3/api_op_DeletePublicAccessBlock.go +++ b/service/s3/api_op_DeletePublicAccessBlock.go @@ -176,7 +176,6 @@ func addDeletePublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options O TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketAccelerateConfiguration.go b/service/s3/api_op_GetBucketAccelerateConfiguration.go index 7d091252e38..d2dff759cd0 100644 --- a/service/s3/api_op_GetBucketAccelerateConfiguration.go +++ b/service/s3/api_op_GetBucketAccelerateConfiguration.go @@ -181,7 +181,6 @@ func addGetBucketAccelerateConfigurationUpdateEndpoint(stack *middleware.Stack, TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketAcl.go b/service/s3/api_op_GetBucketAcl.go index 279335a50c7..96a5043408c 100644 --- a/service/s3/api_op_GetBucketAcl.go +++ b/service/s3/api_op_GetBucketAcl.go @@ -168,7 +168,6 @@ func addGetBucketAclUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketAnalyticsConfiguration.go b/service/s3/api_op_GetBucketAnalyticsConfiguration.go index 80590a22347..3f87c9811f3 100644 --- a/service/s3/api_op_GetBucketAnalyticsConfiguration.go +++ b/service/s3/api_op_GetBucketAnalyticsConfiguration.go @@ -187,7 +187,6 @@ func addGetBucketAnalyticsConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketCors.go b/service/s3/api_op_GetBucketCors.go index f68207794ee..1f291ac0573 100644 --- a/service/s3/api_op_GetBucketCors.go +++ b/service/s3/api_op_GetBucketCors.go @@ -171,7 +171,6 @@ func addGetBucketCorsUpdateEndpoint(stack *middleware.Stack, options Options) er TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketEncryption.go b/service/s3/api_op_GetBucketEncryption.go index ca872e2276d..12507c17bf0 100644 --- a/service/s3/api_op_GetBucketEncryption.go +++ b/service/s3/api_op_GetBucketEncryption.go @@ -181,7 +181,6 @@ func addGetBucketEncryptionUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketIntelligentTieringConfiguration.go b/service/s3/api_op_GetBucketIntelligentTieringConfiguration.go index 82e731ea988..9c5c6abda05 100644 --- a/service/s3/api_op_GetBucketIntelligentTieringConfiguration.go +++ b/service/s3/api_op_GetBucketIntelligentTieringConfiguration.go @@ -187,7 +187,6 @@ func addGetBucketIntelligentTieringConfigurationUpdateEndpoint(stack *middleware TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketInventoryConfiguration.go b/service/s3/api_op_GetBucketInventoryConfiguration.go index 4911e92c03e..64114720225 100644 --- a/service/s3/api_op_GetBucketInventoryConfiguration.go +++ b/service/s3/api_op_GetBucketInventoryConfiguration.go @@ -185,7 +185,6 @@ func addGetBucketInventoryConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketLifecycleConfiguration.go b/service/s3/api_op_GetBucketLifecycleConfiguration.go index 2f11411e990..f64f1486982 100644 --- a/service/s3/api_op_GetBucketLifecycleConfiguration.go +++ b/service/s3/api_op_GetBucketLifecycleConfiguration.go @@ -202,7 +202,6 @@ func addGetBucketLifecycleConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketLocation.go b/service/s3/api_op_GetBucketLocation.go index 7990e01f749..7adda2097ae 100644 --- a/service/s3/api_op_GetBucketLocation.go +++ b/service/s3/api_op_GetBucketLocation.go @@ -241,7 +241,6 @@ func addGetBucketLocationUpdateEndpoint(stack *middleware.Stack, options Options TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketLogging.go b/service/s3/api_op_GetBucketLogging.go index ca285e65f37..2e43477b111 100644 --- a/service/s3/api_op_GetBucketLogging.go +++ b/service/s3/api_op_GetBucketLogging.go @@ -170,7 +170,6 @@ func addGetBucketLoggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketMetricsConfiguration.go b/service/s3/api_op_GetBucketMetricsConfiguration.go index 84ca4f3423b..30025a6685b 100644 --- a/service/s3/api_op_GetBucketMetricsConfiguration.go +++ b/service/s3/api_op_GetBucketMetricsConfiguration.go @@ -192,7 +192,6 @@ func addGetBucketMetricsConfigurationUpdateEndpoint(stack *middleware.Stack, opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketNotificationConfiguration.go b/service/s3/api_op_GetBucketNotificationConfiguration.go index 75e740b43eb..93edf8b6d64 100644 --- a/service/s3/api_op_GetBucketNotificationConfiguration.go +++ b/service/s3/api_op_GetBucketNotificationConfiguration.go @@ -183,7 +183,6 @@ func addGetBucketNotificationConfigurationUpdateEndpoint(stack *middleware.Stack TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketOwnershipControls.go b/service/s3/api_op_GetBucketOwnershipControls.go index 7d0425a015f..ca4144d22a2 100644 --- a/service/s3/api_op_GetBucketOwnershipControls.go +++ b/service/s3/api_op_GetBucketOwnershipControls.go @@ -170,7 +170,6 @@ func addGetBucketOwnershipControlsUpdateEndpoint(stack *middleware.Stack, option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketPolicy.go b/service/s3/api_op_GetBucketPolicy.go index 4d4c1a671a4..4e0d1afa9e3 100644 --- a/service/s3/api_op_GetBucketPolicy.go +++ b/service/s3/api_op_GetBucketPolicy.go @@ -173,7 +173,6 @@ func addGetBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketPolicyStatus.go b/service/s3/api_op_GetBucketPolicyStatus.go index 2cba9cb4ee9..42b3b801226 100644 --- a/service/s3/api_op_GetBucketPolicyStatus.go +++ b/service/s3/api_op_GetBucketPolicyStatus.go @@ -182,7 +182,6 @@ func addGetBucketPolicyStatusUpdateEndpoint(stack *middleware.Stack, options Opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketReplication.go b/service/s3/api_op_GetBucketReplication.go index acf3b3789f0..b03baf4d307 100644 --- a/service/s3/api_op_GetBucketReplication.go +++ b/service/s3/api_op_GetBucketReplication.go @@ -181,7 +181,6 @@ func addGetBucketReplicationUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketRequestPayment.go b/service/s3/api_op_GetBucketRequestPayment.go index 2afcd656fff..18166d4797d 100644 --- a/service/s3/api_op_GetBucketRequestPayment.go +++ b/service/s3/api_op_GetBucketRequestPayment.go @@ -165,7 +165,6 @@ func addGetBucketRequestPaymentUpdateEndpoint(stack *middleware.Stack, options O TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketTagging.go b/service/s3/api_op_GetBucketTagging.go index 51db0ab1286..707284408d8 100644 --- a/service/s3/api_op_GetBucketTagging.go +++ b/service/s3/api_op_GetBucketTagging.go @@ -179,7 +179,6 @@ func addGetBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketVersioning.go b/service/s3/api_op_GetBucketVersioning.go index 7c3cccd85a4..7de1f13b2e8 100644 --- a/service/s3/api_op_GetBucketVersioning.go +++ b/service/s3/api_op_GetBucketVersioning.go @@ -179,7 +179,6 @@ func addGetBucketVersioningUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetBucketWebsite.go b/service/s3/api_op_GetBucketWebsite.go index ebf126c08ab..5e994e391bd 100644 --- a/service/s3/api_op_GetBucketWebsite.go +++ b/service/s3/api_op_GetBucketWebsite.go @@ -183,7 +183,6 @@ func addGetBucketWebsiteUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObject.go b/service/s3/api_op_GetObject.go index 6b900c141d3..81264633167 100644 --- a/service/s3/api_op_GetObject.go +++ b/service/s3/api_op_GetObject.go @@ -496,7 +496,6 @@ func addGetObjectUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectAcl.go b/service/s3/api_op_GetObjectAcl.go index 7abd6a1bbf0..b260a8da960 100644 --- a/service/s3/api_op_GetObjectAcl.go +++ b/service/s3/api_op_GetObjectAcl.go @@ -204,7 +204,6 @@ func addGetObjectAclUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectLegalHold.go b/service/s3/api_op_GetObjectLegalHold.go index 498ee1a4fc5..75a6cfb2953 100644 --- a/service/s3/api_op_GetObjectLegalHold.go +++ b/service/s3/api_op_GetObjectLegalHold.go @@ -184,7 +184,6 @@ func addGetObjectLegalHoldUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectLockConfiguration.go b/service/s3/api_op_GetObjectLockConfiguration.go index 33034d6b975..34f4a62a706 100644 --- a/service/s3/api_op_GetObjectLockConfiguration.go +++ b/service/s3/api_op_GetObjectLockConfiguration.go @@ -169,7 +169,6 @@ func addGetObjectLockConfigurationUpdateEndpoint(stack *middleware.Stack, option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectRetention.go b/service/s3/api_op_GetObjectRetention.go index 99882e3f728..7c23c795edf 100644 --- a/service/s3/api_op_GetObjectRetention.go +++ b/service/s3/api_op_GetObjectRetention.go @@ -184,7 +184,6 @@ func addGetObjectRetentionUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectTagging.go b/service/s3/api_op_GetObjectTagging.go index dfff1fbf833..bad76369356 100644 --- a/service/s3/api_op_GetObjectTagging.go +++ b/service/s3/api_op_GetObjectTagging.go @@ -212,7 +212,6 @@ func addGetObjectTaggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetObjectTorrent.go b/service/s3/api_op_GetObjectTorrent.go index e3cd8e116c7..a8c7cdd495e 100644 --- a/service/s3/api_op_GetObjectTorrent.go +++ b/service/s3/api_op_GetObjectTorrent.go @@ -184,7 +184,6 @@ func addGetObjectTorrentUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_GetPublicAccessBlock.go b/service/s3/api_op_GetPublicAccessBlock.go index 9c273482f3c..16b957aa5ae 100644 --- a/service/s3/api_op_GetPublicAccessBlock.go +++ b/service/s3/api_op_GetPublicAccessBlock.go @@ -189,7 +189,6 @@ func addGetPublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_HeadBucket.go b/service/s3/api_op_HeadBucket.go index 9e4819beaef..f11fcfc92ae 100644 --- a/service/s3/api_op_HeadBucket.go +++ b/service/s3/api_op_HeadBucket.go @@ -486,7 +486,6 @@ func addHeadBucketUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_HeadObject.go b/service/s3/api_op_HeadObject.go index a2f414713b2..fd795d5fea1 100644 --- a/service/s3/api_op_HeadObject.go +++ b/service/s3/api_op_HeadObject.go @@ -789,7 +789,6 @@ func addHeadObjectUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListBucketAnalyticsConfigurations.go b/service/s3/api_op_ListBucketAnalyticsConfigurations.go index 8bc16e360c0..e2b24a91d32 100644 --- a/service/s3/api_op_ListBucketAnalyticsConfigurations.go +++ b/service/s3/api_op_ListBucketAnalyticsConfigurations.go @@ -207,7 +207,6 @@ func addListBucketAnalyticsConfigurationsUpdateEndpoint(stack *middleware.Stack, TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListBucketIntelligentTieringConfigurations.go b/service/s3/api_op_ListBucketIntelligentTieringConfigurations.go index 9f830dfbc71..9309e619dea 100644 --- a/service/s3/api_op_ListBucketIntelligentTieringConfigurations.go +++ b/service/s3/api_op_ListBucketIntelligentTieringConfigurations.go @@ -200,7 +200,6 @@ func addListBucketIntelligentTieringConfigurationsUpdateEndpoint(stack *middlewa TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListBucketInventoryConfigurations.go b/service/s3/api_op_ListBucketInventoryConfigurations.go index 8156bfaff37..8dc32152f11 100644 --- a/service/s3/api_op_ListBucketInventoryConfigurations.go +++ b/service/s3/api_op_ListBucketInventoryConfigurations.go @@ -208,7 +208,6 @@ func addListBucketInventoryConfigurationsUpdateEndpoint(stack *middleware.Stack, TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListBucketMetricsConfigurations.go b/service/s3/api_op_ListBucketMetricsConfigurations.go index c7b6c8ce633..fdd73096d3b 100644 --- a/service/s3/api_op_ListBucketMetricsConfigurations.go +++ b/service/s3/api_op_ListBucketMetricsConfigurations.go @@ -211,7 +211,6 @@ func addListBucketMetricsConfigurationsUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListBuckets.go b/service/s3/api_op_ListBuckets.go index 6c0203d3d02..54abd9fddc9 100644 --- a/service/s3/api_op_ListBuckets.go +++ b/service/s3/api_op_ListBuckets.go @@ -138,7 +138,6 @@ func addListBucketsUpdateEndpoint(stack *middleware.Stack, options Options) erro TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListMultipartUploads.go b/service/s3/api_op_ListMultipartUploads.go index 37aa03f54c4..9fff7280cd6 100644 --- a/service/s3/api_op_ListMultipartUploads.go +++ b/service/s3/api_op_ListMultipartUploads.go @@ -303,7 +303,6 @@ func addListMultipartUploadsUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListObjectVersions.go b/service/s3/api_op_ListObjectVersions.go index 100f542db2c..0013ad01bbe 100644 --- a/service/s3/api_op_ListObjectVersions.go +++ b/service/s3/api_op_ListObjectVersions.go @@ -269,7 +269,6 @@ func addListObjectVersionsUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListObjects.go b/service/s3/api_op_ListObjects.go index 54d5518cf88..37a467ea838 100644 --- a/service/s3/api_op_ListObjects.go +++ b/service/s3/api_op_ListObjects.go @@ -277,7 +277,6 @@ func addListObjectsUpdateEndpoint(stack *middleware.Stack, options Options) erro TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListObjectsV2.go b/service/s3/api_op_ListObjectsV2.go index 57639a01fa4..3ebfee5ce25 100644 --- a/service/s3/api_op_ListObjectsV2.go +++ b/service/s3/api_op_ListObjectsV2.go @@ -397,7 +397,6 @@ func addListObjectsV2UpdateEndpoint(stack *middleware.Stack, options Options) er TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_ListParts.go b/service/s3/api_op_ListParts.go index 3097a581439..6e0df29ec98 100644 --- a/service/s3/api_op_ListParts.go +++ b/service/s3/api_op_ListParts.go @@ -383,7 +383,6 @@ func addListPartsUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketAccelerateConfiguration.go b/service/s3/api_op_PutBucketAccelerateConfiguration.go index b3fd8ef6d95..d8da696598c 100644 --- a/service/s3/api_op_PutBucketAccelerateConfiguration.go +++ b/service/s3/api_op_PutBucketAccelerateConfiguration.go @@ -195,7 +195,6 @@ func addPutBucketAccelerateConfigurationUpdateEndpoint(stack *middleware.Stack, TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketAcl.go b/service/s3/api_op_PutBucketAcl.go index 930a20f52a9..8f619e8dddf 100644 --- a/service/s3/api_op_PutBucketAcl.go +++ b/service/s3/api_op_PutBucketAcl.go @@ -262,6 +262,9 @@ func (c *Client) addOperationPutBucketAclMiddlewares(stack *middleware.Stack, op if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketAclValidationMiddleware(stack); err != nil { return err } @@ -286,9 +289,6 @@ func (c *Client) addOperationPutBucketAclMiddlewares(stack *middleware.Stack, op if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -322,7 +322,6 @@ func addPutBucketAclUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketAnalyticsConfiguration.go b/service/s3/api_op_PutBucketAnalyticsConfiguration.go index 1d88e743fd6..dc78a41ac06 100644 --- a/service/s3/api_op_PutBucketAnalyticsConfiguration.go +++ b/service/s3/api_op_PutBucketAnalyticsConfiguration.go @@ -227,7 +227,6 @@ func addPutBucketAnalyticsConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketCors.go b/service/s3/api_op_PutBucketCors.go index 87355a6bebb..038d9799dc7 100644 --- a/service/s3/api_op_PutBucketCors.go +++ b/service/s3/api_op_PutBucketCors.go @@ -154,6 +154,9 @@ func (c *Client) addOperationPutBucketCorsMiddlewares(stack *middleware.Stack, o if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketCorsValidationMiddleware(stack); err != nil { return err } @@ -178,9 +181,6 @@ func (c *Client) addOperationPutBucketCorsMiddlewares(stack *middleware.Stack, o if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -214,7 +214,6 @@ func addPutBucketCorsUpdateEndpoint(stack *middleware.Stack, options Options) er TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketEncryption.go b/service/s3/api_op_PutBucketEncryption.go index 556b2f51a47..7e6006b2e54 100644 --- a/service/s3/api_op_PutBucketEncryption.go +++ b/service/s3/api_op_PutBucketEncryption.go @@ -141,6 +141,9 @@ func (c *Client) addOperationPutBucketEncryptionMiddlewares(stack *middleware.St if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketEncryptionValidationMiddleware(stack); err != nil { return err } @@ -165,9 +168,6 @@ func (c *Client) addOperationPutBucketEncryptionMiddlewares(stack *middleware.St if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -201,7 +201,6 @@ func addPutBucketEncryptionUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketIntelligentTieringConfiguration.go b/service/s3/api_op_PutBucketIntelligentTieringConfiguration.go index 094817f1351..4ae3a8186e8 100644 --- a/service/s3/api_op_PutBucketIntelligentTieringConfiguration.go +++ b/service/s3/api_op_PutBucketIntelligentTieringConfiguration.go @@ -219,7 +219,6 @@ func addPutBucketIntelligentTieringConfigurationUpdateEndpoint(stack *middleware TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketInventoryConfiguration.go b/service/s3/api_op_PutBucketInventoryConfiguration.go index 3d63878c381..239235c4b5d 100644 --- a/service/s3/api_op_PutBucketInventoryConfiguration.go +++ b/service/s3/api_op_PutBucketInventoryConfiguration.go @@ -228,7 +228,6 @@ func addPutBucketInventoryConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketLifecycleConfiguration.go b/service/s3/api_op_PutBucketLifecycleConfiguration.go index 71db08293d7..13c5955f40a 100644 --- a/service/s3/api_op_PutBucketLifecycleConfiguration.go +++ b/service/s3/api_op_PutBucketLifecycleConfiguration.go @@ -166,6 +166,9 @@ func (c *Client) addOperationPutBucketLifecycleConfigurationMiddlewares(stack *m if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketLifecycleConfigurationValidationMiddleware(stack); err != nil { return err } @@ -190,9 +193,6 @@ func (c *Client) addOperationPutBucketLifecycleConfigurationMiddlewares(stack *m if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -226,7 +226,6 @@ func addPutBucketLifecycleConfigurationUpdateEndpoint(stack *middleware.Stack, o TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketLogging.go b/service/s3/api_op_PutBucketLogging.go index 05e04c019a1..b4f2f00a71c 100644 --- a/service/s3/api_op_PutBucketLogging.go +++ b/service/s3/api_op_PutBucketLogging.go @@ -152,6 +152,9 @@ func (c *Client) addOperationPutBucketLoggingMiddlewares(stack *middleware.Stack if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketLoggingValidationMiddleware(stack); err != nil { return err } @@ -176,9 +179,6 @@ func (c *Client) addOperationPutBucketLoggingMiddlewares(stack *middleware.Stack if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -212,7 +212,6 @@ func addPutBucketLoggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketMetricsConfiguration.go b/service/s3/api_op_PutBucketMetricsConfiguration.go index 22a5da0ed10..d42a6dfdf5b 100644 --- a/service/s3/api_op_PutBucketMetricsConfiguration.go +++ b/service/s3/api_op_PutBucketMetricsConfiguration.go @@ -202,7 +202,6 @@ func addPutBucketMetricsConfigurationUpdateEndpoint(stack *middleware.Stack, opt TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketNotificationConfiguration.go b/service/s3/api_op_PutBucketNotificationConfiguration.go index 706f247ca1d..6322b1081d1 100644 --- a/service/s3/api_op_PutBucketNotificationConfiguration.go +++ b/service/s3/api_op_PutBucketNotificationConfiguration.go @@ -194,7 +194,6 @@ func addPutBucketNotificationConfigurationUpdateEndpoint(stack *middleware.Stack TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketOwnershipControls.go b/service/s3/api_op_PutBucketOwnershipControls.go index f9e0016ae39..394f17d1ac7 100644 --- a/service/s3/api_op_PutBucketOwnershipControls.go +++ b/service/s3/api_op_PutBucketOwnershipControls.go @@ -119,6 +119,9 @@ func (c *Client) addOperationPutBucketOwnershipControlsMiddlewares(stack *middle if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketOwnershipControlsValidationMiddleware(stack); err != nil { return err } @@ -143,9 +146,6 @@ func (c *Client) addOperationPutBucketOwnershipControlsMiddlewares(stack *middle if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -179,7 +179,6 @@ func addPutBucketOwnershipControlsUpdateEndpoint(stack *middleware.Stack, option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketPolicy.go b/service/s3/api_op_PutBucketPolicy.go index 671f767ee2a..090459944fa 100644 --- a/service/s3/api_op_PutBucketPolicy.go +++ b/service/s3/api_op_PutBucketPolicy.go @@ -129,6 +129,9 @@ func (c *Client) addOperationPutBucketPolicyMiddlewares(stack *middleware.Stack, if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketPolicyValidationMiddleware(stack); err != nil { return err } @@ -153,9 +156,6 @@ func (c *Client) addOperationPutBucketPolicyMiddlewares(stack *middleware.Stack, if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -189,7 +189,6 @@ func addPutBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketReplication.go b/service/s3/api_op_PutBucketReplication.go index d1378e733b0..691c08aa3aa 100644 --- a/service/s3/api_op_PutBucketReplication.go +++ b/service/s3/api_op_PutBucketReplication.go @@ -165,6 +165,9 @@ func (c *Client) addOperationPutBucketReplicationMiddlewares(stack *middleware.S if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketReplicationValidationMiddleware(stack); err != nil { return err } @@ -189,9 +192,6 @@ func (c *Client) addOperationPutBucketReplicationMiddlewares(stack *middleware.S if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -225,7 +225,6 @@ func addPutBucketReplicationUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketRequestPayment.go b/service/s3/api_op_PutBucketRequestPayment.go index be7f2c5e65c..36f4b5dd936 100644 --- a/service/s3/api_op_PutBucketRequestPayment.go +++ b/service/s3/api_op_PutBucketRequestPayment.go @@ -122,6 +122,9 @@ func (c *Client) addOperationPutBucketRequestPaymentMiddlewares(stack *middlewar if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketRequestPaymentValidationMiddleware(stack); err != nil { return err } @@ -146,9 +149,6 @@ func (c *Client) addOperationPutBucketRequestPaymentMiddlewares(stack *middlewar if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -182,7 +182,6 @@ func addPutBucketRequestPaymentUpdateEndpoint(stack *middleware.Stack, options O TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketTagging.go b/service/s3/api_op_PutBucketTagging.go index eba210db426..0803795c711 100644 --- a/service/s3/api_op_PutBucketTagging.go +++ b/service/s3/api_op_PutBucketTagging.go @@ -167,6 +167,9 @@ func (c *Client) addOperationPutBucketTaggingMiddlewares(stack *middleware.Stack if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketTaggingValidationMiddleware(stack); err != nil { return err } @@ -191,9 +194,6 @@ func (c *Client) addOperationPutBucketTaggingMiddlewares(stack *middleware.Stack if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -227,7 +227,6 @@ func addPutBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketVersioning.go b/service/s3/api_op_PutBucketVersioning.go index 6806d837588..1f87c2db7f9 100644 --- a/service/s3/api_op_PutBucketVersioning.go +++ b/service/s3/api_op_PutBucketVersioning.go @@ -144,6 +144,9 @@ func (c *Client) addOperationPutBucketVersioningMiddlewares(stack *middleware.St if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketVersioningValidationMiddleware(stack); err != nil { return err } @@ -168,9 +171,6 @@ func (c *Client) addOperationPutBucketVersioningMiddlewares(stack *middleware.St if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -204,7 +204,6 @@ func addPutBucketVersioningUpdateEndpoint(stack *middleware.Stack, options Optio TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutBucketWebsite.go b/service/s3/api_op_PutBucketWebsite.go index 4776ae11b5d..0e1db51fb24 100644 --- a/service/s3/api_op_PutBucketWebsite.go +++ b/service/s3/api_op_PutBucketWebsite.go @@ -180,6 +180,9 @@ func (c *Client) addOperationPutBucketWebsiteMiddlewares(stack *middleware.Stack if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutBucketWebsiteValidationMiddleware(stack); err != nil { return err } @@ -204,9 +207,6 @@ func (c *Client) addOperationPutBucketWebsiteMiddlewares(stack *middleware.Stack if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -240,7 +240,6 @@ func addPutBucketWebsiteUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObject.go b/service/s3/api_op_PutObject.go index 7823bfd993d..bbe52778ef5 100644 --- a/service/s3/api_op_PutObject.go +++ b/service/s3/api_op_PutObject.go @@ -460,7 +460,6 @@ func addPutObjectUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObjectAcl.go b/service/s3/api_op_PutObjectAcl.go index 441e81aa9e7..957aa5663f3 100644 --- a/service/s3/api_op_PutObjectAcl.go +++ b/service/s3/api_op_PutObjectAcl.go @@ -304,6 +304,9 @@ func (c *Client) addOperationPutObjectAclMiddlewares(stack *middleware.Stack, op if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutObjectAclValidationMiddleware(stack); err != nil { return err } @@ -328,9 +331,6 @@ func (c *Client) addOperationPutObjectAclMiddlewares(stack *middleware.Stack, op if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -364,7 +364,6 @@ func addPutObjectAclUpdateEndpoint(stack *middleware.Stack, options Options) err TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObjectLegalHold.go b/service/s3/api_op_PutObjectLegalHold.go index 93161433d68..f7d85b0640e 100644 --- a/service/s3/api_op_PutObjectLegalHold.go +++ b/service/s3/api_op_PutObjectLegalHold.go @@ -138,6 +138,9 @@ func (c *Client) addOperationPutObjectLegalHoldMiddlewares(stack *middleware.Sta if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutObjectLegalHoldValidationMiddleware(stack); err != nil { return err } @@ -162,9 +165,6 @@ func (c *Client) addOperationPutObjectLegalHoldMiddlewares(stack *middleware.Sta if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -198,7 +198,6 @@ func addPutObjectLegalHoldUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObjectLockConfiguration.go b/service/s3/api_op_PutObjectLockConfiguration.go index 503e1422866..461c9b81840 100644 --- a/service/s3/api_op_PutObjectLockConfiguration.go +++ b/service/s3/api_op_PutObjectLockConfiguration.go @@ -135,6 +135,9 @@ func (c *Client) addOperationPutObjectLockConfigurationMiddlewares(stack *middle if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutObjectLockConfigurationValidationMiddleware(stack); err != nil { return err } @@ -159,9 +162,6 @@ func (c *Client) addOperationPutObjectLockConfigurationMiddlewares(stack *middle if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -195,7 +195,6 @@ func addPutObjectLockConfigurationUpdateEndpoint(stack *middleware.Stack, option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObjectRetention.go b/service/s3/api_op_PutObjectRetention.go index 5db15650bce..4be8b901d58 100644 --- a/service/s3/api_op_PutObjectRetention.go +++ b/service/s3/api_op_PutObjectRetention.go @@ -148,6 +148,9 @@ func (c *Client) addOperationPutObjectRetentionMiddlewares(stack *middleware.Sta if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutObjectRetentionValidationMiddleware(stack); err != nil { return err } @@ -172,9 +175,6 @@ func (c *Client) addOperationPutObjectRetentionMiddlewares(stack *middleware.Sta if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -208,7 +208,6 @@ func addPutObjectRetentionUpdateEndpoint(stack *middleware.Stack, options Option TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutObjectTagging.go b/service/s3/api_op_PutObjectTagging.go index 400c3ecf584..d496008a0eb 100644 --- a/service/s3/api_op_PutObjectTagging.go +++ b/service/s3/api_op_PutObjectTagging.go @@ -192,6 +192,9 @@ func (c *Client) addOperationPutObjectTaggingMiddlewares(stack *middleware.Stack if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutObjectTaggingValidationMiddleware(stack); err != nil { return err } @@ -216,9 +219,6 @@ func (c *Client) addOperationPutObjectTaggingMiddlewares(stack *middleware.Stack if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -252,7 +252,6 @@ func addPutObjectTaggingUpdateEndpoint(stack *middleware.Stack, options Options) TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_PutPublicAccessBlock.go b/service/s3/api_op_PutPublicAccessBlock.go index 60f43ef6391..301ebbf5524 100644 --- a/service/s3/api_op_PutPublicAccessBlock.go +++ b/service/s3/api_op_PutPublicAccessBlock.go @@ -141,6 +141,9 @@ func (c *Client) addOperationPutPublicAccessBlockMiddlewares(stack *middleware.S if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpPutPublicAccessBlockValidationMiddleware(stack); err != nil { return err } @@ -165,9 +168,6 @@ func (c *Client) addOperationPutPublicAccessBlockMiddlewares(stack *middleware.S if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -201,7 +201,6 @@ func addPutPublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options Opti TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_RestoreObject.go b/service/s3/api_op_RestoreObject.go index 7d2bb90d7e3..754bbb6b7b6 100644 --- a/service/s3/api_op_RestoreObject.go +++ b/service/s3/api_op_RestoreObject.go @@ -415,7 +415,6 @@ func addRestoreObjectUpdateEndpoint(stack *middleware.Stack, options Options) er TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_UploadPart.go b/service/s3/api_op_UploadPart.go index 6206af295f0..430aa644cf1 100644 --- a/service/s3/api_op_UploadPart.go +++ b/service/s3/api_op_UploadPart.go @@ -352,7 +352,6 @@ func addUploadPartUpdateEndpoint(stack *middleware.Stack, options Options) error TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_UploadPartCopy.go b/service/s3/api_op_UploadPartCopy.go index 82abba5d2bf..b4c89d3cc09 100644 --- a/service/s3/api_op_UploadPartCopy.go +++ b/service/s3/api_op_UploadPartCopy.go @@ -430,7 +430,6 @@ func addUploadPartCopyUpdateEndpoint(stack *middleware.Stack, options Options) e TargetS3ObjectLambda: false, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/api_op_WriteGetObjectResponse.go b/service/s3/api_op_WriteGetObjectResponse.go index bf2b14ff832..0da1d94fb40 100644 --- a/service/s3/api_op_WriteGetObjectResponse.go +++ b/service/s3/api_op_WriteGetObjectResponse.go @@ -399,7 +399,6 @@ func addWriteGetObjectResponseUpdateEndpoint(stack *middleware.Stack, options Op TargetS3ObjectLambda: true, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, }) diff --git a/service/s3/endpoints.go b/service/s3/endpoints.go index 4652db06f87..8df6368cd2f 100644 --- a/service/s3/endpoints.go +++ b/service/s3/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,57 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + + if options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateUnset { + if options.UseDualstack { + options.EndpointOptions.UseDualStackEndpoint = aws.DualStackEndpointStateEnabled + } else { + options.EndpointOptions.UseDualStackEndpoint = aws.DualStackEndpointStateDisabled + } + } + +} diff --git a/service/s3/generated.json b/service/s3/generated.json index d070516de88..a1acc6f854b 100644 --- a/service/s3/generated.json +++ b/service/s3/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding": "v1.0.5", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/aws-sdk-go-v2/service/internal/s3shared": "v1.2.3", diff --git a/service/s3/go.mod b/service/s3/go.mod index d99a9a31849..ac438037fb5 100644 --- a/service/s3/go.mod +++ b/service/s3/go.mod @@ -4,6 +4,8 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.4.0 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.8.0 @@ -13,6 +15,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/s3/internal/configtesting/go.mod b/service/s3/internal/configtesting/go.mod index bc0fe6bc35c..50d29ef86bb 100644 --- a/service/s3/internal/configtesting/go.mod +++ b/service/s3/internal/configtesting/go.mod @@ -15,6 +15,10 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ diff --git a/service/s3/internal/endpoints/endpoints.go b/service/s3/internal/endpoints/endpoints.go index 45737b42754..6da09ea048c 100644 --- a/service/s3/internal/endpoints/endpoints.go +++ b/service/s3/internal/endpoints/endpoints.go @@ -5,14 +5,63 @@ package endpoints import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" "strings" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver S3 endpoint resolver @@ -26,9 +75,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -57,319 +104,670 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, - }, - RegionRegex: partitionRegexp.Aws, - IsRegionalized: true, - Endpoints: endpoints.Endpoints{ - "accesspoint-af-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.af-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-3": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-3.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-southeast-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-southeast-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-southeast-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-southeast-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ca-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ca-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-north-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-north-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-3": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-3.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-me-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.me-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-sa-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.sa-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-us-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-east-1.amazonaws.com", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.api.aws", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-east-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-east-2.amazonaws.com", + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-west-1.amazonaws.com", + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-west-2.amazonaws.com", + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{ + }, + RegionRegex: partitionRegexp.Aws, + IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.af-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "s3.ap-northeast-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "s3.ap-southeast-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-southeast-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "s3.ap-southeast-2.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-southeast-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "s3.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-north-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "s3.eu-west-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-accesspoint-ca-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.ca-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, }, - "fips-accesspoint-us-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-east-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-east-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-west-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "me-south-1": endpoints.Endpoint{}, - "s3-external-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.me-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "s3-external-1", + }: endpoints.Endpoint{ Hostname: "s3-external-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "s3.sa-east-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.sa-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "s3.us-east-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Hostname: "s3.us-west-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "s3.us-west-2.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "accesspoint-cn-north-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.cn-north-1.amazonaws.com.cn", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.cn-north-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.cn-northwest-1.amazonaws.com.cn", }, - "accesspoint-cn-northwest-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.cn-northwest-1.amazonaws.com.cn", - SignatureVersions: []string{"s3v4"}, - }, - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3", "s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "accesspoint-us-gov-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-gov-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-us-gov-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-gov-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "fips-accesspoint-us-gov-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-gov-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "fips-accesspoint-us-gov-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-gov-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "s3-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "s3.us-gov-east-1.amazonaws.com", Protocols: []string{"http", "https"}, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-gov-east-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-gov-east-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "s3.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-gov-west-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-gov-west-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, }, }, } // GetDNSSuffix returns the dnsSuffix URL component for the given partition id -func GetDNSSuffix(id string) (string, error) { +func GetDNSSuffix(id string, options Options) (string, error) { + variant := transformToSharedOptions(options).GetEndpointVariant() switch { case strings.EqualFold(id, "aws"): - return "amazonaws.com", nil + switch variant { + case endpoints.DualStackVariant: + return "api.aws", nil + + case endpoints.FIPSVariant: + return "amazonaws.com", nil + + case endpoints.FIPSVariant | endpoints.DualStackVariant: + return "api.aws", nil + + case 0: + return "amazonaws.com", nil + + default: + return "", fmt.Errorf("unsupported endpoint variant %v, in partition %s", variant, id) + + } case strings.EqualFold(id, "aws-cn"): - return "amazonaws.com.cn", nil + switch variant { + case endpoints.DualStackVariant: + return "amazonwebservices.com.cn", nil + + case endpoints.FIPSVariant: + return "amazonaws.com.cn", nil + + case endpoints.FIPSVariant | endpoints.DualStackVariant: + return "amazonwebservices.com.cn", nil + + case 0: + return "amazonaws.com.cn", nil + + default: + return "", fmt.Errorf("unsupported endpoint variant %v, in partition %s", variant, id) + + } case strings.EqualFold(id, "aws-iso"): - return "c2s.ic.gov", nil + switch variant { + case 0: + return "c2s.ic.gov", nil + + default: + return "", fmt.Errorf("unsupported endpoint variant %v, in partition %s", variant, id) + + } case strings.EqualFold(id, "aws-iso-b"): - return "sc2s.sgov.gov", nil + switch variant { + case 0: + return "sc2s.sgov.gov", nil - case strings.EqualFold(id, "aws-us-gov"): - return "amazonaws.com", nil + default: + return "", fmt.Errorf("unsupported endpoint variant %v, in partition %s", variant, id) - default: - return "", fmt.Errorf("unknown partition") + } - } -} + case strings.EqualFold(id, "aws-us-gov"): + switch variant { + case endpoints.DualStackVariant: + return "api.aws", nil -// GetDNSSuffixFromRegion returns the dnsSuffix URL component for the given -// partition id -func GetDNSSuffixFromRegion(region string) (string, error) { - switch { - case partitionRegexp.Aws.MatchString(region): - return "amazonaws.com", nil + case endpoints.FIPSVariant: + return "amazonaws.com", nil - case partitionRegexp.AwsCn.MatchString(region): - return "amazonaws.com.cn", nil + case endpoints.FIPSVariant | endpoints.DualStackVariant: + return "api.aws", nil - case partitionRegexp.AwsIso.MatchString(region): - return "c2s.ic.gov", nil + case 0: + return "amazonaws.com", nil - case partitionRegexp.AwsIsoB.MatchString(region): - return "sc2s.sgov.gov", nil + default: + return "", fmt.Errorf("unsupported endpoint variant %v, in partition %s", variant, id) - case partitionRegexp.AwsUsGov.MatchString(region): - return "amazonaws.com", nil + } default: - return "", fmt.Errorf("unknown region partition") + return "", fmt.Errorf("unknown partition") } } diff --git a/service/s3control/api_client.go b/service/s3control/api_client.go index c8eb2403d87..493ebb50016 100644 --- a/service/s3control/api_client.go +++ b/service/s3control/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" "github.com/aws/aws-sdk-go-v2/service/internal/s3shared" s3sharedconfig "github.com/aws/aws-sdk-go-v2/service/internal/s3shared/config" smithy "github.com/aws/smithy-go" @@ -97,7 +98,11 @@ type Options struct { // Allows you to enable arn region support for the service. UseARNRegion bool - // Allows you to enable Dualstack endpoint support for the service. + // Allows you to enable dual-stack endpoint support for the service. + // + // Deprecated: Set dual-stack by setting UseDualStackEndpoint on + // EndpointResolverOptions. When EndpointResolverOptions' UseDualStackEndpoint + // field is set it overrides this field value. UseDualstack bool // The HTTP client to invoke API calls with. Defaults to client's default HTTP @@ -140,6 +145,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -190,6 +197,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) resolveUseARNRegion(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -218,7 +227,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -282,6 +291,36 @@ func resolveUseARNRegion(cfg aws.Config, o *Options) error { return nil } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/s3control/api_op_CreateAccessPoint.go b/service/s3control/api_op_CreateAccessPoint.go index cb65cf810dc..a3c38a43c97 100644 --- a/service/s3control/api_op_CreateAccessPoint.go +++ b/service/s3control/api_op_CreateAccessPoint.go @@ -271,7 +271,6 @@ func addCreateAccessPointUpdateEndpoint(stack *middleware.Stack, options Options }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_CreateAccessPointForObjectLambda.go b/service/s3control/api_op_CreateAccessPointForObjectLambda.go index e14e528e773..3e42d611651 100644 --- a/service/s3control/api_op_CreateAccessPointForObjectLambda.go +++ b/service/s3control/api_op_CreateAccessPointForObjectLambda.go @@ -229,7 +229,6 @@ func addCreateAccessPointForObjectLambdaUpdateEndpoint(stack *middleware.Stack, }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_CreateBucket.go b/service/s3control/api_op_CreateBucket.go index f12441fb5ac..49e434770b6 100644 --- a/service/s3control/api_op_CreateBucket.go +++ b/service/s3control/api_op_CreateBucket.go @@ -187,6 +187,9 @@ func (c *Client) addOperationCreateBucketMiddlewares(stack *middleware.Stack, op if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addOpCreateBucketValidationMiddleware(stack); err != nil { return err } @@ -208,9 +211,6 @@ func (c *Client) addOperationCreateBucketMiddlewares(stack *middleware.Stack, op if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -252,7 +252,6 @@ func addCreateBucketUpdateEndpoint(stack *middleware.Stack, options Options) err }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_CreateJob.go b/service/s3control/api_op_CreateJob.go index 6006c141f39..cd678f8685a 100644 --- a/service/s3control/api_op_CreateJob.go +++ b/service/s3control/api_op_CreateJob.go @@ -312,7 +312,6 @@ func addCreateJobUpdateEndpoint(stack *middleware.Stack, options Options) error }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_CreateMultiRegionAccessPoint.go b/service/s3control/api_op_CreateMultiRegionAccessPoint.go index d6af98d2491..ebf247a17a2 100644 --- a/service/s3control/api_op_CreateMultiRegionAccessPoint.go +++ b/service/s3control/api_op_CreateMultiRegionAccessPoint.go @@ -141,6 +141,9 @@ func (c *Client) addOperationCreateMultiRegionAccessPointMiddlewares(stack *midd if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opCreateMultiRegionAccessPointMiddleware(stack); err != nil { return err } @@ -168,9 +171,6 @@ func (c *Client) addOperationCreateMultiRegionAccessPointMiddlewares(stack *midd if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -286,7 +286,6 @@ func addCreateMultiRegionAccessPointUpdateEndpoint(stack *middleware.Stack, opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteAccessPoint.go b/service/s3control/api_op_DeleteAccessPoint.go index 298fb9af124..cd74d377456 100644 --- a/service/s3control/api_op_DeleteAccessPoint.go +++ b/service/s3control/api_op_DeleteAccessPoint.go @@ -242,7 +242,6 @@ func addDeleteAccessPointUpdateEndpoint(stack *middleware.Stack, options Options }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteAccessPointForObjectLambda.go b/service/s3control/api_op_DeleteAccessPointForObjectLambda.go index 4d91ec0a86a..630f102f0ee 100644 --- a/service/s3control/api_op_DeleteAccessPointForObjectLambda.go +++ b/service/s3control/api_op_DeleteAccessPointForObjectLambda.go @@ -216,7 +216,6 @@ func addDeleteAccessPointForObjectLambdaUpdateEndpoint(stack *middleware.Stack, }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteAccessPointPolicy.go b/service/s3control/api_op_DeleteAccessPointPolicy.go index 7951a5372c2..93e2bdcce01 100644 --- a/service/s3control/api_op_DeleteAccessPointPolicy.go +++ b/service/s3control/api_op_DeleteAccessPointPolicy.go @@ -239,7 +239,6 @@ func addDeleteAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, options O }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteAccessPointPolicyForObjectLambda.go b/service/s3control/api_op_DeleteAccessPointPolicyForObjectLambda.go index 17599045234..81aa2dd0744 100644 --- a/service/s3control/api_op_DeleteAccessPointPolicyForObjectLambda.go +++ b/service/s3control/api_op_DeleteAccessPointPolicyForObjectLambda.go @@ -213,7 +213,6 @@ func addDeleteAccessPointPolicyForObjectLambdaUpdateEndpoint(stack *middleware.S }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteBucket.go b/service/s3control/api_op_DeleteBucket.go index 60559bbb3f9..15932aa3d7d 100644 --- a/service/s3control/api_op_DeleteBucket.go +++ b/service/s3control/api_op_DeleteBucket.go @@ -249,7 +249,6 @@ func addDeleteBucketUpdateEndpoint(stack *middleware.Stack, options Options) err }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteBucketLifecycleConfiguration.go b/service/s3control/api_op_DeleteBucketLifecycleConfiguration.go index c0845e890a6..74f85da7849 100644 --- a/service/s3control/api_op_DeleteBucketLifecycleConfiguration.go +++ b/service/s3control/api_op_DeleteBucketLifecycleConfiguration.go @@ -253,7 +253,6 @@ func addDeleteBucketLifecycleConfigurationUpdateEndpoint(stack *middleware.Stack }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteBucketPolicy.go b/service/s3control/api_op_DeleteBucketPolicy.go index 1bbe6b7d321..8ae0522088b 100644 --- a/service/s3control/api_op_DeleteBucketPolicy.go +++ b/service/s3control/api_op_DeleteBucketPolicy.go @@ -258,7 +258,6 @@ func addDeleteBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Option }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteBucketTagging.go b/service/s3control/api_op_DeleteBucketTagging.go index eae6675781d..692b1016bcc 100644 --- a/service/s3control/api_op_DeleteBucketTagging.go +++ b/service/s3control/api_op_DeleteBucketTagging.go @@ -246,7 +246,6 @@ func addDeleteBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Optio }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteJobTagging.go b/service/s3control/api_op_DeleteJobTagging.go index 724e619999d..6dc00007416 100644 --- a/service/s3control/api_op_DeleteJobTagging.go +++ b/service/s3control/api_op_DeleteJobTagging.go @@ -219,7 +219,6 @@ func addDeleteJobTaggingUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteMultiRegionAccessPoint.go b/service/s3control/api_op_DeleteMultiRegionAccessPoint.go index 7d63cd0615e..09be36210b4 100644 --- a/service/s3control/api_op_DeleteMultiRegionAccessPoint.go +++ b/service/s3control/api_op_DeleteMultiRegionAccessPoint.go @@ -138,6 +138,9 @@ func (c *Client) addOperationDeleteMultiRegionAccessPointMiddlewares(stack *midd if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opDeleteMultiRegionAccessPointMiddleware(stack); err != nil { return err } @@ -165,9 +168,6 @@ func (c *Client) addOperationDeleteMultiRegionAccessPointMiddlewares(stack *midd if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -283,7 +283,6 @@ func addDeleteMultiRegionAccessPointUpdateEndpoint(stack *middleware.Stack, opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeletePublicAccessBlock.go b/service/s3control/api_op_DeletePublicAccessBlock.go index eaa819e7c4b..5242e4aef46 100644 --- a/service/s3control/api_op_DeletePublicAccessBlock.go +++ b/service/s3control/api_op_DeletePublicAccessBlock.go @@ -209,7 +209,6 @@ func addDeletePublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options O }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteStorageLensConfiguration.go b/service/s3control/api_op_DeleteStorageLensConfiguration.go index 6475a6a53f1..3143c0bb91e 100644 --- a/service/s3control/api_op_DeleteStorageLensConfiguration.go +++ b/service/s3control/api_op_DeleteStorageLensConfiguration.go @@ -211,7 +211,6 @@ func addDeleteStorageLensConfigurationUpdateEndpoint(stack *middleware.Stack, op }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DeleteStorageLensConfigurationTagging.go b/service/s3control/api_op_DeleteStorageLensConfigurationTagging.go index 12c047bbacc..47e1bce56da 100644 --- a/service/s3control/api_op_DeleteStorageLensConfigurationTagging.go +++ b/service/s3control/api_op_DeleteStorageLensConfigurationTagging.go @@ -211,7 +211,6 @@ func addDeleteStorageLensConfigurationTaggingUpdateEndpoint(stack *middleware.St }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DescribeJob.go b/service/s3control/api_op_DescribeJob.go index 815c00856a4..a5b299919cf 100644 --- a/service/s3control/api_op_DescribeJob.go +++ b/service/s3control/api_op_DescribeJob.go @@ -227,7 +227,6 @@ func addDescribeJobUpdateEndpoint(stack *middleware.Stack, options Options) erro }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_DescribeMultiRegionAccessPointOperation.go b/service/s3control/api_op_DescribeMultiRegionAccessPointOperation.go index 22bc4a7fac7..92f786c31aa 100644 --- a/service/s3control/api_op_DescribeMultiRegionAccessPointOperation.go +++ b/service/s3control/api_op_DescribeMultiRegionAccessPointOperation.go @@ -126,6 +126,9 @@ func (c *Client) addOperationDescribeMultiRegionAccessPointOperationMiddlewares( if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opDescribeMultiRegionAccessPointOperationMiddleware(stack); err != nil { return err } @@ -150,9 +153,6 @@ func (c *Client) addOperationDescribeMultiRegionAccessPointOperationMiddlewares( if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -235,7 +235,6 @@ func addDescribeMultiRegionAccessPointOperationUpdateEndpoint(stack *middleware. }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPoint.go b/service/s3control/api_op_GetAccessPoint.go index 76bff3eb73f..7ff39419160 100644 --- a/service/s3control/api_op_GetAccessPoint.go +++ b/service/s3control/api_op_GetAccessPoint.go @@ -285,7 +285,6 @@ func addGetAccessPointUpdateEndpoint(stack *middleware.Stack, options Options) e }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointConfigurationForObjectLambda.go b/service/s3control/api_op_GetAccessPointConfigurationForObjectLambda.go index bdc6c316671..93bfc2f8d36 100644 --- a/service/s3control/api_op_GetAccessPointConfigurationForObjectLambda.go +++ b/service/s3control/api_op_GetAccessPointConfigurationForObjectLambda.go @@ -215,7 +215,6 @@ func addGetAccessPointConfigurationForObjectLambdaUpdateEndpoint(stack *middlewa }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointForObjectLambda.go b/service/s3control/api_op_GetAccessPointForObjectLambda.go index 70290d464bc..dbb3923a70b 100644 --- a/service/s3control/api_op_GetAccessPointForObjectLambda.go +++ b/service/s3control/api_op_GetAccessPointForObjectLambda.go @@ -230,7 +230,6 @@ func addGetAccessPointForObjectLambdaUpdateEndpoint(stack *middleware.Stack, opt }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointPolicy.go b/service/s3control/api_op_GetAccessPointPolicy.go index 60e6a8da583..6d83fb7c504 100644 --- a/service/s3control/api_op_GetAccessPointPolicy.go +++ b/service/s3control/api_op_GetAccessPointPolicy.go @@ -236,7 +236,6 @@ func addGetAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, options Opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointPolicyForObjectLambda.go b/service/s3control/api_op_GetAccessPointPolicyForObjectLambda.go index 948e6ea6ee5..a3ae5b89901 100644 --- a/service/s3control/api_op_GetAccessPointPolicyForObjectLambda.go +++ b/service/s3control/api_op_GetAccessPointPolicyForObjectLambda.go @@ -217,7 +217,6 @@ func addGetAccessPointPolicyForObjectLambdaUpdateEndpoint(stack *middleware.Stac }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointPolicyStatus.go b/service/s3control/api_op_GetAccessPointPolicyStatus.go index 9db1706b0e1..fee3f750700 100644 --- a/service/s3control/api_op_GetAccessPointPolicyStatus.go +++ b/service/s3control/api_op_GetAccessPointPolicyStatus.go @@ -212,7 +212,6 @@ func addGetAccessPointPolicyStatusUpdateEndpoint(stack *middleware.Stack, option }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetAccessPointPolicyStatusForObjectLambda.go b/service/s3control/api_op_GetAccessPointPolicyStatusForObjectLambda.go index f3de1adb6b2..96c597b684a 100644 --- a/service/s3control/api_op_GetAccessPointPolicyStatusForObjectLambda.go +++ b/service/s3control/api_op_GetAccessPointPolicyStatusForObjectLambda.go @@ -214,7 +214,6 @@ func addGetAccessPointPolicyStatusForObjectLambdaUpdateEndpoint(stack *middlewar }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetBucket.go b/service/s3control/api_op_GetBucket.go index 3403a18b91b..d1a088deb43 100644 --- a/service/s3control/api_op_GetBucket.go +++ b/service/s3control/api_op_GetBucket.go @@ -263,7 +263,6 @@ func addGetBucketUpdateEndpoint(stack *middleware.Stack, options Options) error }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetBucketLifecycleConfiguration.go b/service/s3control/api_op_GetBucketLifecycleConfiguration.go index 32b2a8b61eb..6ca88c2fa70 100644 --- a/service/s3control/api_op_GetBucketLifecycleConfiguration.go +++ b/service/s3control/api_op_GetBucketLifecycleConfiguration.go @@ -273,7 +273,6 @@ func addGetBucketLifecycleConfigurationUpdateEndpoint(stack *middleware.Stack, o }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetBucketPolicy.go b/service/s3control/api_op_GetBucketPolicy.go index 7fce738061f..f20c5aefecc 100644 --- a/service/s3control/api_op_GetBucketPolicy.go +++ b/service/s3control/api_op_GetBucketPolicy.go @@ -264,7 +264,6 @@ func addGetBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetBucketTagging.go b/service/s3control/api_op_GetBucketTagging.go index d7a716b0406..292c6f6e3a9 100644 --- a/service/s3control/api_op_GetBucketTagging.go +++ b/service/s3control/api_op_GetBucketTagging.go @@ -261,7 +261,6 @@ func addGetBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetJobTagging.go b/service/s3control/api_op_GetJobTagging.go index 8cfbc3db3bd..b79ff1db00f 100644 --- a/service/s3control/api_op_GetJobTagging.go +++ b/service/s3control/api_op_GetJobTagging.go @@ -223,7 +223,6 @@ func addGetJobTaggingUpdateEndpoint(stack *middleware.Stack, options Options) er }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetMultiRegionAccessPoint.go b/service/s3control/api_op_GetMultiRegionAccessPoint.go index f21ac09deb1..5891d9be743 100644 --- a/service/s3control/api_op_GetMultiRegionAccessPoint.go +++ b/service/s3control/api_op_GetMultiRegionAccessPoint.go @@ -130,6 +130,9 @@ func (c *Client) addOperationGetMultiRegionAccessPointMiddlewares(stack *middlew if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opGetMultiRegionAccessPointMiddleware(stack); err != nil { return err } @@ -154,9 +157,6 @@ func (c *Client) addOperationGetMultiRegionAccessPointMiddlewares(stack *middlew if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -239,7 +239,6 @@ func addGetMultiRegionAccessPointUpdateEndpoint(stack *middleware.Stack, options }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetMultiRegionAccessPointPolicy.go b/service/s3control/api_op_GetMultiRegionAccessPointPolicy.go index ef63531c6d0..b62e5495b7d 100644 --- a/service/s3control/api_op_GetMultiRegionAccessPointPolicy.go +++ b/service/s3control/api_op_GetMultiRegionAccessPointPolicy.go @@ -121,6 +121,9 @@ func (c *Client) addOperationGetMultiRegionAccessPointPolicyMiddlewares(stack *m if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opGetMultiRegionAccessPointPolicyMiddleware(stack); err != nil { return err } @@ -145,9 +148,6 @@ func (c *Client) addOperationGetMultiRegionAccessPointPolicyMiddlewares(stack *m if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -230,7 +230,6 @@ func addGetMultiRegionAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, o }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetMultiRegionAccessPointPolicyStatus.go b/service/s3control/api_op_GetMultiRegionAccessPointPolicyStatus.go index 630729ba413..c82df7ddfc2 100644 --- a/service/s3control/api_op_GetMultiRegionAccessPointPolicyStatus.go +++ b/service/s3control/api_op_GetMultiRegionAccessPointPolicyStatus.go @@ -125,6 +125,9 @@ func (c *Client) addOperationGetMultiRegionAccessPointPolicyStatusMiddlewares(st if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opGetMultiRegionAccessPointPolicyStatusMiddleware(stack); err != nil { return err } @@ -149,9 +152,6 @@ func (c *Client) addOperationGetMultiRegionAccessPointPolicyStatusMiddlewares(st if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -234,7 +234,6 @@ func addGetMultiRegionAccessPointPolicyStatusUpdateEndpoint(stack *middleware.St }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetPublicAccessBlock.go b/service/s3control/api_op_GetPublicAccessBlock.go index 2558f766af6..54dedd37c3c 100644 --- a/service/s3control/api_op_GetPublicAccessBlock.go +++ b/service/s3control/api_op_GetPublicAccessBlock.go @@ -215,7 +215,6 @@ func addGetPublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options Opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetStorageLensConfiguration.go b/service/s3control/api_op_GetStorageLensConfiguration.go index c4e8152138c..257cae3ec2e 100644 --- a/service/s3control/api_op_GetStorageLensConfiguration.go +++ b/service/s3control/api_op_GetStorageLensConfiguration.go @@ -215,7 +215,6 @@ func addGetStorageLensConfigurationUpdateEndpoint(stack *middleware.Stack, optio }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_GetStorageLensConfigurationTagging.go b/service/s3control/api_op_GetStorageLensConfigurationTagging.go index f5bcba57f25..bcf6fec2847 100644 --- a/service/s3control/api_op_GetStorageLensConfigurationTagging.go +++ b/service/s3control/api_op_GetStorageLensConfigurationTagging.go @@ -216,7 +216,6 @@ func addGetStorageLensConfigurationTaggingUpdateEndpoint(stack *middleware.Stack }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListAccessPoints.go b/service/s3control/api_op_ListAccessPoints.go index 65310a537a4..9d2f6db59de 100644 --- a/service/s3control/api_op_ListAccessPoints.go +++ b/service/s3control/api_op_ListAccessPoints.go @@ -352,7 +352,6 @@ func addListAccessPointsUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListAccessPointsForObjectLambda.go b/service/s3control/api_op_ListAccessPointsForObjectLambda.go index 863bd67d3ff..e8efbd5fec5 100644 --- a/service/s3control/api_op_ListAccessPointsForObjectLambda.go +++ b/service/s3control/api_op_ListAccessPointsForObjectLambda.go @@ -324,7 +324,6 @@ func addListAccessPointsForObjectLambdaUpdateEndpoint(stack *middleware.Stack, o }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListJobs.go b/service/s3control/api_op_ListJobs.go index 6556d02456a..91f20d8415c 100644 --- a/service/s3control/api_op_ListJobs.go +++ b/service/s3control/api_op_ListJobs.go @@ -326,7 +326,6 @@ func addListJobsUpdateEndpoint(stack *middleware.Stack, options Options) error { }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListMultiRegionAccessPoints.go b/service/s3control/api_op_ListMultiRegionAccessPoints.go index 029fe776821..4707615ea91 100644 --- a/service/s3control/api_op_ListMultiRegionAccessPoints.go +++ b/service/s3control/api_op_ListMultiRegionAccessPoints.go @@ -134,6 +134,9 @@ func (c *Client) addOperationListMultiRegionAccessPointsMiddlewares(stack *middl if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opListMultiRegionAccessPointsMiddleware(stack); err != nil { return err } @@ -158,9 +161,6 @@ func (c *Client) addOperationListMultiRegionAccessPointsMiddlewares(stack *middl if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -328,7 +328,6 @@ func addListMultiRegionAccessPointsUpdateEndpoint(stack *middleware.Stack, optio }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListRegionalBuckets.go b/service/s3control/api_op_ListRegionalBuckets.go index 0b5e62b6c49..6f7510480db 100644 --- a/service/s3control/api_op_ListRegionalBuckets.go +++ b/service/s3control/api_op_ListRegionalBuckets.go @@ -319,7 +319,6 @@ func addListRegionalBucketsUpdateEndpoint(stack *middleware.Stack, options Optio }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_ListStorageLensConfigurations.go b/service/s3control/api_op_ListStorageLensConfigurations.go index a01eef869e4..deeaf0ca4b7 100644 --- a/service/s3control/api_op_ListStorageLensConfigurations.go +++ b/service/s3control/api_op_ListStorageLensConfigurations.go @@ -296,7 +296,6 @@ func addListStorageLensConfigurationsUpdateEndpoint(stack *middleware.Stack, opt }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutAccessPointConfigurationForObjectLambda.go b/service/s3control/api_op_PutAccessPointConfigurationForObjectLambda.go index 45466cf8e70..753f5e804b9 100644 --- a/service/s3control/api_op_PutAccessPointConfigurationForObjectLambda.go +++ b/service/s3control/api_op_PutAccessPointConfigurationForObjectLambda.go @@ -215,7 +215,6 @@ func addPutAccessPointConfigurationForObjectLambdaUpdateEndpoint(stack *middlewa }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutAccessPointPolicy.go b/service/s3control/api_op_PutAccessPointPolicy.go index 15e67d3fec3..b811cd5d71d 100644 --- a/service/s3control/api_op_PutAccessPointPolicy.go +++ b/service/s3control/api_op_PutAccessPointPolicy.go @@ -251,7 +251,6 @@ func addPutAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, options Opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutAccessPointPolicyForObjectLambda.go b/service/s3control/api_op_PutAccessPointPolicyForObjectLambda.go index 4c3d5b0fbbf..b2c301e85fe 100644 --- a/service/s3control/api_op_PutAccessPointPolicyForObjectLambda.go +++ b/service/s3control/api_op_PutAccessPointPolicyForObjectLambda.go @@ -220,7 +220,6 @@ func addPutAccessPointPolicyForObjectLambdaUpdateEndpoint(stack *middleware.Stac }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutBucketLifecycleConfiguration.go b/service/s3control/api_op_PutBucketLifecycleConfiguration.go index b0ce81408af..7bbd48d2402 100644 --- a/service/s3control/api_op_PutBucketLifecycleConfiguration.go +++ b/service/s3control/api_op_PutBucketLifecycleConfiguration.go @@ -123,6 +123,9 @@ func (c *Client) addOperationPutBucketLifecycleConfigurationMiddlewares(stack *m if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opPutBucketLifecycleConfigurationMiddleware(stack); err != nil { return err } @@ -147,9 +150,6 @@ func (c *Client) addOperationPutBucketLifecycleConfigurationMiddlewares(stack *m if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -244,7 +244,6 @@ func addPutBucketLifecycleConfigurationUpdateEndpoint(stack *middleware.Stack, o }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutBucketPolicy.go b/service/s3control/api_op_PutBucketPolicy.go index 1f51a296a8e..18d261117a4 100644 --- a/service/s3control/api_op_PutBucketPolicy.go +++ b/service/s3control/api_op_PutBucketPolicy.go @@ -149,6 +149,9 @@ func (c *Client) addOperationPutBucketPolicyMiddlewares(stack *middleware.Stack, if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opPutBucketPolicyMiddleware(stack); err != nil { return err } @@ -173,9 +176,6 @@ func (c *Client) addOperationPutBucketPolicyMiddlewares(stack *middleware.Stack, if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -270,7 +270,6 @@ func addPutBucketPolicyUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutBucketTagging.go b/service/s3control/api_op_PutBucketTagging.go index 80c6a122f52..6757132ed2c 100644 --- a/service/s3control/api_op_PutBucketTagging.go +++ b/service/s3control/api_op_PutBucketTagging.go @@ -182,6 +182,9 @@ func (c *Client) addOperationPutBucketTaggingMiddlewares(stack *middleware.Stack if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opPutBucketTaggingMiddleware(stack); err != nil { return err } @@ -206,9 +209,6 @@ func (c *Client) addOperationPutBucketTaggingMiddlewares(stack *middleware.Stack if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -303,7 +303,6 @@ func addPutBucketTaggingUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutJobTagging.go b/service/s3control/api_op_PutJobTagging.go index 085204fa604..e9922b69258 100644 --- a/service/s3control/api_op_PutJobTagging.go +++ b/service/s3control/api_op_PutJobTagging.go @@ -266,7 +266,6 @@ func addPutJobTaggingUpdateEndpoint(stack *middleware.Stack, options Options) er }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutMultiRegionAccessPointPolicy.go b/service/s3control/api_op_PutMultiRegionAccessPointPolicy.go index e3066c2f42d..545ab4a18ae 100644 --- a/service/s3control/api_op_PutMultiRegionAccessPointPolicy.go +++ b/service/s3control/api_op_PutMultiRegionAccessPointPolicy.go @@ -128,6 +128,9 @@ func (c *Client) addOperationPutMultiRegionAccessPointPolicyMiddlewares(stack *m if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } + if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { + return err + } if err = addEndpointPrefix_opPutMultiRegionAccessPointPolicyMiddleware(stack); err != nil { return err } @@ -155,9 +158,6 @@ func (c *Client) addOperationPutMultiRegionAccessPointPolicyMiddlewares(stack *m if err = addRequestResponseLogging(stack, options); err != nil { return err } - if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { - return err - } return nil } @@ -273,7 +273,6 @@ func addPutMultiRegionAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, o }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutPublicAccessBlock.go b/service/s3control/api_op_PutPublicAccessBlock.go index d99a4b34db0..589f508b36c 100644 --- a/service/s3control/api_op_PutPublicAccessBlock.go +++ b/service/s3control/api_op_PutPublicAccessBlock.go @@ -216,7 +216,6 @@ func addPutPublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options Opti }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutStorageLensConfiguration.go b/service/s3control/api_op_PutStorageLensConfiguration.go index dd3af6ec858..a0dae69a225 100644 --- a/service/s3control/api_op_PutStorageLensConfiguration.go +++ b/service/s3control/api_op_PutStorageLensConfiguration.go @@ -220,7 +220,6 @@ func addPutStorageLensConfigurationUpdateEndpoint(stack *middleware.Stack, optio }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_PutStorageLensConfigurationTagging.go b/service/s3control/api_op_PutStorageLensConfigurationTagging.go index f6c543d0bd0..b160dd3dd86 100644 --- a/service/s3control/api_op_PutStorageLensConfigurationTagging.go +++ b/service/s3control/api_op_PutStorageLensConfigurationTagging.go @@ -218,7 +218,6 @@ func addPutStorageLensConfigurationTaggingUpdateEndpoint(stack *middleware.Stack }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_UpdateJobPriority.go b/service/s3control/api_op_UpdateJobPriority.go index a178006e2aa..b10e5f995df 100644 --- a/service/s3control/api_op_UpdateJobPriority.go +++ b/service/s3control/api_op_UpdateJobPriority.go @@ -237,7 +237,6 @@ func addUpdateJobPriorityUpdateEndpoint(stack *middleware.Stack, options Options }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/api_op_UpdateJobStatus.go b/service/s3control/api_op_UpdateJobStatus.go index 1d5153e3bc9..aa257a2bd42 100644 --- a/service/s3control/api_op_UpdateJobStatus.go +++ b/service/s3control/api_op_UpdateJobStatus.go @@ -242,7 +242,6 @@ func addUpdateJobStatusUpdateEndpoint(stack *middleware.Stack, options Options) }, EndpointResolver: options.EndpointResolver, EndpointResolverOptions: options.EndpointOptions, - UseDualstack: options.UseDualstack, UseARNRegion: options.UseARNRegion, }) } diff --git a/service/s3control/endpoints.go b/service/s3control/endpoints.go index 7889cc861f7..6dd40effad0 100644 --- a/service/s3control/endpoints.go +++ b/service/s3control/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,57 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + + if options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateUnset { + if options.UseDualstack { + options.EndpointOptions.UseDualStackEndpoint = aws.DualStackEndpointStateEnabled + } else { + options.EndpointOptions.UseDualStackEndpoint = aws.DualStackEndpointStateDisabled + } + } + +} diff --git a/service/s3control/generated.json b/service/s3control/generated.json index db96dff1a33..16f0a20a499 100644 --- a/service/s3control/generated.json +++ b/service/s3control/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/s3shared": "v1.2.3", "github.com/aws/smithy-go": "v1.4.0" }, diff --git a/service/s3control/go.mod b/service/s3control/go.mod index b08479bfeb0..d8da253bc94 100644 --- a/service/s3control/go.mod +++ b/service/s3control/go.mod @@ -4,10 +4,16 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.8.0 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../service/internal/s3shared/ diff --git a/service/s3control/internal/endpoints/endpoints.go b/service/s3control/internal/endpoints/endpoints.go index da3226a374a..adfeabdf631 100644 --- a/service/s3control/internal/endpoints/endpoints.go +++ b/service/s3control/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver S3 Control endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,253 +102,749 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "s3-control.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-control.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-northeast-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-northeast-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-northeast-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, }, - "ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-northeast-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-northeast-3.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, }, - "ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-northeast-3.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-3", + }, + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-south-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-south-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-southeast-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-southeast-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "s3-control.ap-southeast-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ap-southeast-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Hostname: "s3-control.ca-central-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "ca-central-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "s3-control-fips.ca-central-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.ca-central-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.ca-central-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "ca-central-1-fips", + }: endpoints.Endpoint{ + Hostname: "s3-control-fips.ca-central-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "s3-control.eu-central-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.eu-central-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "eu-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ Hostname: "s3-control.eu-north-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.eu-north-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "eu-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "s3-control.eu-west-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.eu-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "s3-control.eu-west-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.eu-west-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ Hostname: "s3-control.eu-west-3.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.eu-west-3.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-3", + }, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "s3-control.sa-east-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.sa-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "sa-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "s3-control.us-east-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "s3-control-fips.us-east-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ + Hostname: "s3-control-fips.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "s3-control.us-east-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-east-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.us-east-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-east-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "s3-control-fips.us-east-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Hostname: "s3-control.us-west-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "s3-control-fips.us-west-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "s3-control.us-west-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, }, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "s3-control-fips.us-west-2.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "s3-control.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-control.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ Hostname: "s3-control.cn-north-1.amazonaws.com.cn", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, }, - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.cn-north-1.amazonaws.com.cn", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "cn-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "s3-control.cn-northwest-1.amazonaws.com.cn", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", }, }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.cn-northwest-1.amazonaws.com.cn", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "cn-northwest-1", + }, + }, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "s3-control.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3-control.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "s3-control.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3-control.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "s3-control.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-control.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "s3-control.us-gov-east-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-gov-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.us-gov-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-gov-east-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "s3-control-fips.us-gov-east-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "s3-control.us-gov-west-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-control-fips.dualstack.us-gov-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-control-fips.us-gov-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-control.dualstack.us-gov-west-1.amazonaws.com", + SignatureVersions: []string{"s3v4"}, + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "s3-control-fips.us-gov-west-1.amazonaws.com", SignatureVersions: []string{"s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/s3control/internal/endpoints/s3/endpoints.go b/service/s3control/internal/endpoints/s3/endpoints.go index 633cfcbde91..fb1f9d2c0a1 100644 --- a/service/s3control/internal/endpoints/s3/endpoints.go +++ b/service/s3control/internal/endpoints/s3/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver S3 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,270 +102,583 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, - }, - RegionRegex: partitionRegexp.Aws, - IsRegionalized: true, - Endpoints: endpoints.Endpoints{ - "accesspoint-af-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.af-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-northeast-3": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-northeast-3.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-southeast-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-southeast-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ap-southeast-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ap-southeast-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-ca-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.ca-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-north-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-north-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-eu-west-3": endpoints.Endpoint{ - Hostname: "s3-accesspoint.eu-west-3.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-me-south-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.me-south-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-sa-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.sa-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-us-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-east-1.amazonaws.com", + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.api.aws", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-east-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-east-2.amazonaws.com", + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-west-1.amazonaws.com", + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "accesspoint-us-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-west-2.amazonaws.com", + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{ + }, + RegionRegex: partitionRegexp.Aws, + IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.af-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "s3.ap-northeast-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-northeast-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "s3.ap-southeast-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-southeast-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "s3.ap-southeast-2.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ap-southeast-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "s3.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-north-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "s3.eu-west-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-accesspoint-ca-central-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.ca-central-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, }, - "fips-accesspoint-us-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.eu-west-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-east-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-east-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + Deprecated: aws.TrueTernary, }, - "fips-accesspoint-us-west-2": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-west-2.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + Deprecated: aws.TrueTernary, }, - "me-south-1": endpoints.Endpoint{}, - "s3-external-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.me-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "s3-external-1", + }: endpoints.Endpoint{ Hostname: "s3-external-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "s3.sa-east-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.sa-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "s3.us-east-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-east-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Hostname: "s3.us-west-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-west-1.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "s3.us-west-2.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-west-2.amazonaws.com", + SignatureVersions: []string{"s3", "s3v4"}, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "accesspoint-cn-north-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.cn-north-1.amazonaws.com.cn", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.cn-north-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.cn-northwest-1.amazonaws.com.cn", }, - "accesspoint-cn-northwest-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.cn-northwest-1.amazonaws.com.cn", - SignatureVersions: []string{"s3v4"}, - }, - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, SignatureVersions: []string{"s3v4"}, }, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "s3.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"s3", "s3v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"s3", "s3v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "accesspoint-us-gov-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-gov-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "accesspoint-us-gov-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint.us-gov-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "fips-accesspoint-us-gov-east-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-gov-east-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, - }, - "fips-accesspoint-us-gov-west-1": endpoints.Endpoint{ - Hostname: "s3-accesspoint-fips.us-gov-west-1.amazonaws.com", - SignatureVersions: []string{"s3v4"}, + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ + Hostname: "s3-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "s3-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "s3.us-gov-east-1.amazonaws.com", Protocols: []string{"http", "https"}, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-gov-east-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-gov-east-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "s3.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-fips.us-gov-west-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3.dualstack.us-gov-west-1.amazonaws.com", + Protocols: []string{"http", "https"}, + }, }, }, } diff --git a/service/s3outposts/api_client.go b/service/s3outposts/api_client.go index 9ecde547005..03b59069585 100644 --- a/service/s3outposts/api_client.go +++ b/service/s3outposts/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/s3outposts/endpoints.go b/service/s3outposts/endpoints.go index e714cc118b0..9d7f2d72a8a 100644 --- a/service/s3outposts/endpoints.go +++ b/service/s3outposts/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/s3outposts/generated.json b/service/s3outposts/generated.json index a5f324d30a5..e0a1bad9929 100644 --- a/service/s3outposts/generated.json +++ b/service/s3outposts/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/s3outposts/go.mod b/service/s3outposts/go.mod index 1a96ac96489..1f93764b708 100644 --- a/service/s3outposts/go.mod +++ b/service/s3outposts/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/s3outposts/internal/endpoints/endpoints.go b/service/s3outposts/internal/endpoints/endpoints.go index 42d9859a2af..3470e2265c5 100644 --- a/service/s3outposts/internal/endpoints/endpoints.go +++ b/service/s3outposts/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver S3Outposts endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,198 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "s3-outposts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-outposts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-outposts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "s3-outposts.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-outposts-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-outposts.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "s3-outposts.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3-outposts.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "s3-outposts.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "s3-outposts.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "s3-outposts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "s3-outposts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "s3-outposts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "s3-outposts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sagemaker/api_client.go b/service/sagemaker/api_client.go index 6ca36ad59e0..53239854014 100644 --- a/service/sagemaker/api_client.go +++ b/service/sagemaker/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/sagemaker/endpoints.go b/service/sagemaker/endpoints.go index 3b81b93393a..080ba56fd42 100644 --- a/service/sagemaker/endpoints.go +++ b/service/sagemaker/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sagemaker/generated.json b/service/sagemaker/generated.json index 49481379b20..f1b5e3d9d2a 100644 --- a/service/sagemaker/generated.json +++ b/service/sagemaker/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/sagemaker/go.mod b/service/sagemaker/go.mod index 04df4ee7f6f..fd6643ab225 100644 --- a/service/sagemaker/go.mod +++ b/service/sagemaker/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sagemaker/internal/endpoints/endpoints.go b/service/sagemaker/internal/endpoints/endpoints.go index dedb5bbba69..97f69126af7 100644 --- a/service/sagemaker/internal/endpoints/endpoints.go +++ b/service/sagemaker/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SageMaker endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,120 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "api.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api-fips.sagemaker.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "api-fips.sagemaker.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api-fips.sagemaker.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "api-fips.sagemaker.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api-fips.sagemaker.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "api-fips.sagemaker.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api-fips.sagemaker.us-west-2.amazonaws.com", }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "api-fips.sagemaker.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "api.sagemaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.sagemaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "api.sagemaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.sagemaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "api.sagemaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "api.sagemaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "api.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "api.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "api.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "api-fips.sagemaker.us-gov-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "api-fips.sagemaker.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips-secondary", + }: endpoints.Endpoint{ + Hostname: "api.sagemaker.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-secondary", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, }, - "us-gov-west-1-fips-secondary": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-secondary", + Variant: endpoints.FIPSVariant, + }: { Hostname: "api.sagemaker.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/sagemakera2iruntime/api_client.go b/service/sagemakera2iruntime/api_client.go index 518f8f27931..83fbeb5fe19 100644 --- a/service/sagemakera2iruntime/api_client.go +++ b/service/sagemakera2iruntime/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sagemakera2iruntime/endpoints.go b/service/sagemakera2iruntime/endpoints.go index ed95370cd96..7f01143e2d5 100644 --- a/service/sagemakera2iruntime/endpoints.go +++ b/service/sagemakera2iruntime/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sagemakera2iruntime/generated.json b/service/sagemakera2iruntime/generated.json index e4e8a8fed6b..a1b3fd72dcb 100644 --- a/service/sagemakera2iruntime/generated.json +++ b/service/sagemakera2iruntime/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sagemakera2iruntime/go.mod b/service/sagemakera2iruntime/go.mod index bb9a5ece909..ebe2612ab68 100644 --- a/service/sagemakera2iruntime/go.mod +++ b/service/sagemakera2iruntime/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sagemakera2iruntime/internal/endpoints/endpoints.go b/service/sagemakera2iruntime/internal/endpoints/endpoints.go index f36a95b6257..90b731876a7 100644 --- a/service/sagemakera2iruntime/internal/endpoints/endpoints.go +++ b/service/sagemakera2iruntime/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SageMaker A2I Runtime endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "a2i-runtime.sagemaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "a2i-runtime.sagemaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "a2i-runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "a2i-runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sagemakeredge/api_client.go b/service/sagemakeredge/api_client.go index 437a727db85..4e7736ebd84 100644 --- a/service/sagemakeredge/api_client.go +++ b/service/sagemakeredge/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sagemakeredge/endpoints.go b/service/sagemakeredge/endpoints.go index d0f21577e34..82fbfdb76fb 100644 --- a/service/sagemakeredge/endpoints.go +++ b/service/sagemakeredge/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sagemakeredge/generated.json b/service/sagemakeredge/generated.json index 6f632d65fd0..e698d6099b0 100644 --- a/service/sagemakeredge/generated.json +++ b/service/sagemakeredge/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sagemakeredge/go.mod b/service/sagemakeredge/go.mod index c243950a941..484a039bdce 100644 --- a/service/sagemakeredge/go.mod +++ b/service/sagemakeredge/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sagemakeredge/internal/endpoints/endpoints.go b/service/sagemakeredge/internal/endpoints/endpoints.go index 9820e2ad5c3..20d3326fa08 100644 --- a/service/sagemakeredge/internal/endpoints/endpoints.go +++ b/service/sagemakeredge/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Sagemaker Edge endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "edge.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "edge.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "edge.sagemaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "edge.sagemaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "edge.sagemaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "edge.sagemaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "edge.sagemaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "edge.sagemaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "edge.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "edge.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "edge.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sagemakerfeaturestoreruntime/api_client.go b/service/sagemakerfeaturestoreruntime/api_client.go index d80bbd88249..aa81974a4c1 100644 --- a/service/sagemakerfeaturestoreruntime/api_client.go +++ b/service/sagemakerfeaturestoreruntime/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sagemakerfeaturestoreruntime/endpoints.go b/service/sagemakerfeaturestoreruntime/endpoints.go index e90ec96a628..c0cf7a0988e 100644 --- a/service/sagemakerfeaturestoreruntime/endpoints.go +++ b/service/sagemakerfeaturestoreruntime/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sagemakerfeaturestoreruntime/generated.json b/service/sagemakerfeaturestoreruntime/generated.json index 08775c77091..1aa543c96e1 100644 --- a/service/sagemakerfeaturestoreruntime/generated.json +++ b/service/sagemakerfeaturestoreruntime/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sagemakerfeaturestoreruntime/go.mod b/service/sagemakerfeaturestoreruntime/go.mod index 5e62bb5e794..041fb3e2457 100644 --- a/service/sagemakerfeaturestoreruntime/go.mod +++ b/service/sagemakerfeaturestoreruntime/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sagemakerfeaturestoreruntime/internal/endpoints/endpoints.go b/service/sagemakerfeaturestoreruntime/internal/endpoints/endpoints.go index 1939942c2fd..b28a9a09205 100644 --- a/service/sagemakerfeaturestoreruntime/internal/endpoints/endpoints.go +++ b/service/sagemakerfeaturestoreruntime/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SageMaker FeatureStore Runtime endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "featurestore-runtime.sagemaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "featurestore-runtime.sagemaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "featurestore-runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "featurestore-runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sagemakerruntime/api_client.go b/service/sagemakerruntime/api_client.go index af94010c1ed..8c8a0b381e8 100644 --- a/service/sagemakerruntime/api_client.go +++ b/service/sagemakerruntime/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sagemakerruntime/endpoints.go b/service/sagemakerruntime/endpoints.go index 6197e5c7f07..8e1b061c1cd 100644 --- a/service/sagemakerruntime/endpoints.go +++ b/service/sagemakerruntime/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sagemakerruntime/generated.json b/service/sagemakerruntime/generated.json index c6cb2a6a1b2..18a0f5681b3 100644 --- a/service/sagemakerruntime/generated.json +++ b/service/sagemakerruntime/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sagemakerruntime/go.mod b/service/sagemakerruntime/go.mod index 5dfcbee2adb..d4c510fe7de 100644 --- a/service/sagemakerruntime/go.mod +++ b/service/sagemakerruntime/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sagemakerruntime/internal/endpoints/endpoints.go b/service/sagemakerruntime/internal/endpoints/endpoints.go index bcabfd26e66..03c07eec9d6 100644 --- a/service/sagemakerruntime/internal/endpoints/endpoints.go +++ b/service/sagemakerruntime/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SageMaker Runtime endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,114 +102,292 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.sagemaker.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.sagemaker.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.sagemaker.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.sagemaker.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.sagemaker.us-west-1.amazonaws.com", }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.sagemaker.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime-fips.sagemaker.us-west-2.amazonaws.com", }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "runtime-fips.sagemaker.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.sagemaker.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime.sagemaker.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.sagemaker.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime.sagemaker.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.sagemaker.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "runtime.sagemaker.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "runtime.sagemaker.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "runtime.sagemaker-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "runtime.sagemaker.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "runtime.sagemaker.us-gov-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "runtime.sagemaker.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/savingsplans/api_client.go b/service/savingsplans/api_client.go index cfc14a36b72..176a0dddf90 100644 --- a/service/savingsplans/api_client.go +++ b/service/savingsplans/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/savingsplans/endpoints.go b/service/savingsplans/endpoints.go index 95923c14342..efdf7443e4d 100644 --- a/service/savingsplans/endpoints.go +++ b/service/savingsplans/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/savingsplans/generated.json b/service/savingsplans/generated.json index 7511af13d52..4207ccf037d 100644 --- a/service/savingsplans/generated.json +++ b/service/savingsplans/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/savingsplans/go.mod b/service/savingsplans/go.mod index fe2dd56ade4..fe2d9c0ac28 100644 --- a/service/savingsplans/go.mod +++ b/service/savingsplans/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/savingsplans/internal/endpoints/endpoints.go b/service/savingsplans/internal/endpoints/endpoints.go index 540f6cc5e96..3f4e3c9942b 100644 --- a/service/savingsplans/internal/endpoints/endpoints.go +++ b/service/savingsplans/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver savingsplans endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,16 +102,43 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "savingsplans.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "savingsplans.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "savingsplans-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "savingsplans-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "savingsplans.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "savingsplans.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -74,40 +148,98 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "savingsplans.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "savingsplans.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "savingsplans-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "savingsplans-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "savingsplans.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "savingsplans.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "savingsplans.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "savingsplans.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "savingsplans.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "savingsplans.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "savingsplans.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "savingsplans-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "savingsplans-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "savingsplans.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/schemas/api_client.go b/service/schemas/api_client.go index a6b82e2433d..6be800b9f57 100644 --- a/service/schemas/api_client.go +++ b/service/schemas/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/schemas/endpoints.go b/service/schemas/endpoints.go index 29e0b507f75..df30c14f7ab 100644 --- a/service/schemas/endpoints.go +++ b/service/schemas/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/schemas/generated.json b/service/schemas/generated.json index 942ef135ba0..9223241cc93 100644 --- a/service/schemas/generated.json +++ b/service/schemas/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/schemas/go.mod b/service/schemas/go.mod index 5a30618d444..10ce2e365f0 100644 --- a/service/schemas/go.mod +++ b/service/schemas/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/schemas/internal/endpoints/endpoints.go b/service/schemas/internal/endpoints/endpoints.go index 5766470fb0b..36eb38377ee 100644 --- a/service/schemas/internal/endpoints/endpoints.go +++ b/service/schemas/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver schemas endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,186 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "schemas.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "schemas.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "schemas-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "schemas-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "schemas.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "schemas.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "schemas.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "schemas-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "schemas-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "schemas.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "schemas.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "schemas.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "schemas.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "schemas.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "schemas.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "schemas.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "schemas-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "schemas-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "schemas.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/secretsmanager/api_client.go b/service/secretsmanager/api_client.go index 0a022d4f375..b7ae6d3d604 100644 --- a/service/secretsmanager/api_client.go +++ b/service/secretsmanager/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/secretsmanager/endpoints.go b/service/secretsmanager/endpoints.go index a9c5bb12112..1361eff9ad0 100644 --- a/service/secretsmanager/endpoints.go +++ b/service/secretsmanager/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/secretsmanager/generated.json b/service/secretsmanager/generated.json index 84246ee5b96..44abbb25ecc 100644 --- a/service/secretsmanager/generated.json +++ b/service/secretsmanager/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/secretsmanager/go.mod b/service/secretsmanager/go.mod index 86b7377be9d..7abff1edeff 100644 --- a/service/secretsmanager/go.mod +++ b/service/secretsmanager/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/secretsmanager/internal/endpoints/endpoints.go b/service/secretsmanager/internal/endpoints/endpoints.go index 135bc8194ab..8d731665543 100644 --- a/service/secretsmanager/internal/endpoints/endpoints.go +++ b/service/secretsmanager/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Secrets Manager endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,310 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "secretsmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "secretsmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "secretsmanager.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "secretsmanager.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "secretsmanager.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "secretsmanager.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "secretsmanager.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "secretsmanager.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "secretsmanager.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "secretsmanager-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "secretsmanager.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "secretsmanager-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "secretsmanager-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/securityhub/api_client.go b/service/securityhub/api_client.go index e9e884bdb3b..ebed23376c9 100644 --- a/service/securityhub/api_client.go +++ b/service/securityhub/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/securityhub/endpoints.go b/service/securityhub/endpoints.go index a0d2c14a570..110d5a94a97 100644 --- a/service/securityhub/endpoints.go +++ b/service/securityhub/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/securityhub/generated.json b/service/securityhub/generated.json index 6ea5dc441dc..8ebb16f5e0d 100644 --- a/service/securityhub/generated.json +++ b/service/securityhub/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/securityhub/go.mod b/service/securityhub/go.mod index faaa5c60f6a..818166283e6 100644 --- a/service/securityhub/go.mod +++ b/service/securityhub/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/securityhub/internal/endpoints/endpoints.go b/service/securityhub/internal/endpoints/endpoints.go index deda44feb9f..b5b47f7d2dd 100644 --- a/service/securityhub/internal/endpoints/endpoints.go +++ b/service/securityhub/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SecurityHub endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "securityhub.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "securityhub.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "securityhub-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "securityhub.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "securityhub.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "securityhub.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "securityhub-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "securityhub.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "securityhub.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "securityhub.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "securityhub.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "securityhub.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "securityhub.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "securityhub.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "securityhub-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "securityhub.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "securityhub-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "securityhub-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/serverlessapplicationrepository/api_client.go b/service/serverlessapplicationrepository/api_client.go index e9495306f7c..161e09a2d92 100644 --- a/service/serverlessapplicationrepository/api_client.go +++ b/service/serverlessapplicationrepository/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/serverlessapplicationrepository/endpoints.go b/service/serverlessapplicationrepository/endpoints.go index ea4a74d5624..a0e4e2d590a 100644 --- a/service/serverlessapplicationrepository/endpoints.go +++ b/service/serverlessapplicationrepository/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/serverlessapplicationrepository/generated.json b/service/serverlessapplicationrepository/generated.json index 94bb3f62285..dea57d6af17 100644 --- a/service/serverlessapplicationrepository/generated.json +++ b/service/serverlessapplicationrepository/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/serverlessapplicationrepository/go.mod b/service/serverlessapplicationrepository/go.mod index 688958ec32f..c05c718b75c 100644 --- a/service/serverlessapplicationrepository/go.mod +++ b/service/serverlessapplicationrepository/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/serverlessapplicationrepository/internal/endpoints/endpoints.go b/service/serverlessapplicationrepository/internal/endpoints/endpoints.go index 9d202f7fb1d..3b6c794fb39 100644 --- a/service/serverlessapplicationrepository/internal/endpoints/endpoints.go +++ b/service/serverlessapplicationrepository/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ServerlessApplicationRepository endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,253 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "serverlessrepo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "serverlessrepo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "serverlessrepo.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "serverlessrepo.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Protocols: []string{"https"}, }, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "serverlessrepo.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "serverlessrepo.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "serverlessrepo.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "serverlessrepo.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "serverlessrepo.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "serverlessrepo-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "serverlessrepo.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "serverlessrepo.us-gov-east-1.amazonaws.com", Protocols: []string{"https"}, CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "serverlessrepo.us-gov-west-1.amazonaws.com", Protocols: []string{"https"}, CredentialScope: endpoints.CredentialScope{ diff --git a/service/servicecatalog/api_client.go b/service/servicecatalog/api_client.go index 5fb3e2bf365..4dacd28d95a 100644 --- a/service/servicecatalog/api_client.go +++ b/service/servicecatalog/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/servicecatalog/endpoints.go b/service/servicecatalog/endpoints.go index 75d5571a2f4..09eecb829ad 100644 --- a/service/servicecatalog/endpoints.go +++ b/service/servicecatalog/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/servicecatalog/generated.json b/service/servicecatalog/generated.json index 1ce18921a3e..3a50edc3634 100644 --- a/service/servicecatalog/generated.json +++ b/service/servicecatalog/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/servicecatalog/go.mod b/service/servicecatalog/go.mod index 89ec9d577f9..27e76b267cd 100644 --- a/service/servicecatalog/go.mod +++ b/service/servicecatalog/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/servicecatalog/internal/endpoints/endpoints.go b/service/servicecatalog/internal/endpoints/endpoints.go index b4154e61f78..582afe6c509 100644 --- a/service/servicecatalog/internal/endpoints/endpoints.go +++ b/service/servicecatalog/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Service Catalog endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,305 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicecatalog.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicecatalog.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "servicecatalog-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/servicecatalogappregistry/api_client.go b/service/servicecatalogappregistry/api_client.go index 63ffee2afa4..2ed448d0b47 100644 --- a/service/servicecatalogappregistry/api_client.go +++ b/service/servicecatalogappregistry/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/servicecatalogappregistry/endpoints.go b/service/servicecatalogappregistry/endpoints.go index 25e7582fc68..b230610d305 100644 --- a/service/servicecatalogappregistry/endpoints.go +++ b/service/servicecatalogappregistry/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/servicecatalogappregistry/generated.json b/service/servicecatalogappregistry/generated.json index 5c307acaebc..49329112df5 100644 --- a/service/servicecatalogappregistry/generated.json +++ b/service/servicecatalogappregistry/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/servicecatalogappregistry/go.mod b/service/servicecatalogappregistry/go.mod index ee1e21b73cb..7a7c89d4daf 100644 --- a/service/servicecatalogappregistry/go.mod +++ b/service/servicecatalogappregistry/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/servicecatalogappregistry/internal/endpoints/endpoints.go b/service/servicecatalogappregistry/internal/endpoints/endpoints.go index 23274e5e77a..71ecda55776 100644 --- a/service/servicecatalogappregistry/internal/endpoints/endpoints.go +++ b/service/servicecatalogappregistry/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Service Catalog AppRegistry endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,120 +102,310 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog-appregistry.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog-appregistry.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog-appregistry.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog-appregistry.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog-appregistry.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicecatalog-appregistry.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog-appregistry.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicecatalog-appregistry.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "servicecatalog-appregistry.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicecatalog-appregistry-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicecatalog-appregistry.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "servicecatalog-appregistry.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicecatalog-appregistry.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/servicediscovery/api_client.go b/service/servicediscovery/api_client.go index 0dd42246641..4219b5b5796 100644 --- a/service/servicediscovery/api_client.go +++ b/service/servicediscovery/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/servicediscovery/endpoints.go b/service/servicediscovery/endpoints.go index 55e01c3f4be..78f3bfd00cc 100644 --- a/service/servicediscovery/endpoints.go +++ b/service/servicediscovery/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/servicediscovery/generated.json b/service/servicediscovery/generated.json index ba79a9aa527..3bdee9ec404 100644 --- a/service/servicediscovery/generated.json +++ b/service/servicediscovery/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/servicediscovery/go.mod b/service/servicediscovery/go.mod index 2719e384086..5da639ec0b1 100644 --- a/service/servicediscovery/go.mod +++ b/service/servicediscovery/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/servicediscovery/internal/endpoints/endpoints.go b/service/servicediscovery/internal/endpoints/endpoints.go index 2b4ea4d8aa5..5d5d2681693 100644 --- a/service/servicediscovery/internal/endpoints/endpoints.go +++ b/service/servicediscovery/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver ServiceDiscovery endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,94 +102,267 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "servicediscovery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicediscovery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicediscovery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "servicediscovery-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "servicediscovery", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "servicediscovery", + Variant: endpoints.FIPSVariant, + }: { Hostname: "servicediscovery-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "servicediscovery-fips", + }: endpoints.Endpoint{ + Hostname: "servicediscovery-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "servicediscovery.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicediscovery-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicediscovery.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "servicediscovery.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicediscovery.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "servicediscovery.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicediscovery.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "servicediscovery.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicediscovery-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicediscovery-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicediscovery.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "servicediscovery-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "servicediscovery", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "servicediscovery", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicediscovery-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "servicediscovery-fips", + }: endpoints.Endpoint{ Hostname: "servicediscovery-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/servicequotas/api_client.go b/service/servicequotas/api_client.go index 922a215dca9..482387ef386 100644 --- a/service/servicequotas/api_client.go +++ b/service/servicequotas/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/servicequotas/endpoints.go b/service/servicequotas/endpoints.go index 29f9d7c0157..815646d89ac 100644 --- a/service/servicequotas/endpoints.go +++ b/service/servicequotas/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/servicequotas/generated.json b/service/servicequotas/generated.json index 7568a09d2a0..a02bbaabdae 100644 --- a/service/servicequotas/generated.json +++ b/service/servicequotas/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/servicequotas/go.mod b/service/servicequotas/go.mod index 5f162d0d97a..e9f0d48fe4c 100644 --- a/service/servicequotas/go.mod +++ b/service/servicequotas/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/servicequotas/internal/endpoints/endpoints.go b/service/servicequotas/internal/endpoints/endpoints.go index d0b2be34714..196c3a1d1eb 100644 --- a/service/servicequotas/internal/endpoints/endpoints.go +++ b/service/servicequotas/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Service Quotas endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,91 +102,238 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "servicequotas.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicequotas.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicequotas-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicequotas-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicequotas.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "servicequotas.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicequotas.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicequotas-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicequotas-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicequotas.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "servicequotas.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicequotas.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "servicequotas.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "servicequotas.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "servicequotas.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "servicequotas.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicequotas-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "servicequotas-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "servicequotas.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "servicequotas.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "servicequotas.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicequotas.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "servicequotas.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/ses/api_client.go b/service/ses/api_client.go index 932b82a693e..eb52c50a836 100644 --- a/service/ses/api_client.go +++ b/service/ses/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ses/endpoints.go b/service/ses/endpoints.go index 1e0cee2eccc..732e314a5f8 100644 --- a/service/ses/endpoints.go +++ b/service/ses/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ses/generated.json b/service/ses/generated.json index b1a0d92d460..54f9aa40532 100644 --- a/service/ses/generated.json +++ b/service/ses/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/ses/go.mod b/service/ses/go.mod index 604cd2e56ce..845fd59c8a4 100644 --- a/service/ses/go.mod +++ b/service/ses/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ses/internal/endpoints/endpoints.go b/service/ses/internal/endpoints/endpoints.go index e280612c5f1..db7a03fab38 100644 --- a/service/ses/internal/endpoints/endpoints.go +++ b/service/ses/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SES endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,175 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "email-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/sesv2/api_client.go b/service/sesv2/api_client.go index 717605dc2a8..537179430a1 100644 --- a/service/sesv2/api_client.go +++ b/service/sesv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sesv2/endpoints.go b/service/sesv2/endpoints.go index f8223f47441..099fa81d23e 100644 --- a/service/sesv2/endpoints.go +++ b/service/sesv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sesv2/generated.json b/service/sesv2/generated.json index 1ef9f9449fa..52197d70453 100644 --- a/service/sesv2/generated.json +++ b/service/sesv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sesv2/go.mod b/service/sesv2/go.mod index 3aded5cdb38..6c39ed1ec98 100644 --- a/service/sesv2/go.mod +++ b/service/sesv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sesv2/internal/endpoints/endpoints.go b/service/sesv2/internal/endpoints/endpoints.go index 39f2c478657..f7366767fbe 100644 --- a/service/sesv2/internal/endpoints/endpoints.go +++ b/service/sesv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SESv2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,69 +102,175 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "email.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "email.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "email.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "email-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "email.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "email-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "email-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/sfn/api_client.go b/service/sfn/api_client.go index 31c0e42a31a..59c3e467b89 100644 --- a/service/sfn/api_client.go +++ b/service/sfn/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sfn/endpoints.go b/service/sfn/endpoints.go index 3ab47c7f416..154608def01 100644 --- a/service/sfn/endpoints.go +++ b/service/sfn/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sfn/generated.json b/service/sfn/generated.json index b8c334e8a25..0c6c1891436 100644 --- a/service/sfn/generated.json +++ b/service/sfn/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sfn/go.mod b/service/sfn/go.mod index 274b7a6238d..f80c5a6a4c9 100644 --- a/service/sfn/go.mod +++ b/service/sfn/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sfn/internal/endpoints/endpoints.go b/service/sfn/internal/endpoints/endpoints.go index f0275a1c346..acfc580949c 100644 --- a/service/sfn/internal/endpoints/endpoints.go +++ b/service/sfn/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SFN endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,126 +102,319 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "states.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "states.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "states-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "states.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "states-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "states-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "states-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "states-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "states.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "states.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "states-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "states.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "states.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "states.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "states.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "states.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "states.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "states.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "states-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "states.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "states-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "states.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "states.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/shield/api_client.go b/service/shield/api_client.go index 80e49830212..bbef796acb7 100644 --- a/service/shield/api_client.go +++ b/service/shield/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/shield/endpoints.go b/service/shield/endpoints.go index a3159a0eb45..4ce9bba1520 100644 --- a/service/shield/endpoints.go +++ b/service/shield/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/shield/generated.json b/service/shield/generated.json index c3580a2363e..ddd533adb7d 100644 --- a/service/shield/generated.json +++ b/service/shield/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/shield/go.mod b/service/shield/go.mod index 68cef3f24da..9c1ed7d9cb1 100644 --- a/service/shield/go.mod +++ b/service/shield/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/shield/internal/endpoints/endpoints.go b/service/shield/internal/endpoints/endpoints.go index a3a57043001..6181d95e66a 100644 --- a/service/shield/internal/endpoints/endpoints.go +++ b/service/shield/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Shield endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,65 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "shield.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "shield.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "shield-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "shield-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "shield.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "shield.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "fips-aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + Variant: endpoints.FIPSVariant, + }: { Hostname: "shield-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, + endpoints.EndpointKey{ + Region: "fips-aws-global", + }: endpoints.Endpoint{ + Hostname: "shield-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "shield.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "shield.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "shield-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "shield-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "shield.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "shield.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "shield.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "shield.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "shield.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "shield.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "shield.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "shield-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "shield-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "shield.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/signer/api_client.go b/service/signer/api_client.go index b49591fc4ea..2d000c9d6b2 100644 --- a/service/signer/api_client.go +++ b/service/signer/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/signer/endpoints.go b/service/signer/endpoints.go index 8ad3ad86c9c..fcbd961124b 100644 --- a/service/signer/endpoints.go +++ b/service/signer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/signer/generated.json b/service/signer/generated.json index 99e1fbbf2c5..d191c0e2b1d 100644 --- a/service/signer/generated.json +++ b/service/signer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/signer/go.mod b/service/signer/go.mod index 3f20fc8d1ea..ae772480388 100644 --- a/service/signer/go.mod +++ b/service/signer/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/signer/internal/endpoints/endpoints.go b/service/signer/internal/endpoints/endpoints.go index dc152d985ea..b0c16a834f2 100644 --- a/service/signer/internal/endpoints/endpoints.go +++ b/service/signer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver signer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,213 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "signer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "signer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "signer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "signer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "signer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "signer.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "signer.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "signer-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "signer-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "signer.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "signer.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "signer.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "signer.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "signer.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "signer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "signer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "signer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "signer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "signer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + }, }, } diff --git a/service/sms/api_client.go b/service/sms/api_client.go index 0a25910a520..67883b3c244 100644 --- a/service/sms/api_client.go +++ b/service/sms/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sms/endpoints.go b/service/sms/endpoints.go index 75ec50f9773..83a582a8154 100644 --- a/service/sms/endpoints.go +++ b/service/sms/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sms/generated.json b/service/sms/generated.json index 07f299d9743..cc698c0a704 100644 --- a/service/sms/generated.json +++ b/service/sms/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sms/go.mod b/service/sms/go.mod index 1dedc5da9b3..f84e3bcf9ee 100644 --- a/service/sms/go.mod +++ b/service/sms/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sms/internal/endpoints/endpoints.go b/service/sms/internal/endpoints/endpoints.go index b3ac36db355..03eff23720b 100644 --- a/service/sms/internal/endpoints/endpoints.go +++ b/service/sms/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SMS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,118 +102,303 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sms.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sms.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sms.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sms.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sms.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sms.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sms.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sms-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sms.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "sms-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sms-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/snowball/api_client.go b/service/snowball/api_client.go index 0c57656e515..b703d667767 100644 --- a/service/snowball/api_client.go +++ b/service/snowball/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/snowball/endpoints.go b/service/snowball/endpoints.go index 59ff60c0600..ec113a1a837 100644 --- a/service/snowball/endpoints.go +++ b/service/snowball/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/snowball/generated.json b/service/snowball/generated.json index f332ebb1606..246768828d6 100644 --- a/service/snowball/generated.json +++ b/service/snowball/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/snowball/go.mod b/service/snowball/go.mod index 8a19f335bb0..48aaf35efc7 100644 --- a/service/snowball/go.mod +++ b/service/snowball/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/snowball/internal/endpoints/endpoints.go b/service/snowball/internal/endpoints/endpoints.go index 366f890c651..a0ed0a966b2 100644 --- a/service/snowball/internal/endpoints/endpoints.go +++ b/service/snowball/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Snowball endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,208 +102,523 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "snowball.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snowball.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snowball-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snowball.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-northeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-northeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-northeast-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-south-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-southeast-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ap-southeast-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.eu-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.eu-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.eu-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.eu-west-3.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "fips-ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-northeast-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-south-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-central-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-2", + }: endpoints.Endpoint{ Hostname: "snowball-fips.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-3", + }: endpoints.Endpoint{ Hostname: "snowball-fips.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, + Deprecated: aws.TrueTernary, }, - "fips-sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-sa-east-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.sa-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "snowball.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snowball.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snowball-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snowball.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, - "fips-cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.cn-north-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.cn-northwest-1.amazonaws.com.cn", + }, + endpoints.EndpointKey{ + Region: "fips-cn-north-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, + Deprecated: aws.TrueTernary, }, - "fips-cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "snowball.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "snowball.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "snowball.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "snowball.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "snowball.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snowball.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snowball-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snowball.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "snowball-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snowball-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/snowdevicemanagement/api_client.go b/service/snowdevicemanagement/api_client.go index 56b35d69d2f..9fc2036a3ed 100644 --- a/service/snowdevicemanagement/api_client.go +++ b/service/snowdevicemanagement/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/snowdevicemanagement/endpoints.go b/service/snowdevicemanagement/endpoints.go index a8af3ddd5ac..fe66744a09c 100644 --- a/service/snowdevicemanagement/endpoints.go +++ b/service/snowdevicemanagement/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/snowdevicemanagement/generated.json b/service/snowdevicemanagement/generated.json index d7a41413975..7479492feb9 100644 --- a/service/snowdevicemanagement/generated.json +++ b/service/snowdevicemanagement/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/snowdevicemanagement/go.mod b/service/snowdevicemanagement/go.mod index 72e981aee35..b849ebaf963 100644 --- a/service/snowdevicemanagement/go.mod +++ b/service/snowdevicemanagement/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/snowdevicemanagement/internal/endpoints/endpoints.go b/service/snowdevicemanagement/internal/endpoints/endpoints.go index cc2c705a095..78a28086438 100644 --- a/service/snowdevicemanagement/internal/endpoints/endpoints.go +++ b/service/snowdevicemanagement/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Snow Device Management endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,147 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "snow-device-management.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snow-device-management-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snow-device-management.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "snow-device-management.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snow-device-management-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snow-device-management.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "snow-device-management.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "snow-device-management.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "snow-device-management.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "snow-device-management.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "snow-device-management.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "snow-device-management-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "snow-device-management-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "snow-device-management.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sns/api_client.go b/service/sns/api_client.go index 3fdcbd496ec..efea317a59c 100644 --- a/service/sns/api_client.go +++ b/service/sns/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sns/endpoints.go b/service/sns/endpoints.go index e83b1b5832b..f88bfe55b04 100644 --- a/service/sns/endpoints.go +++ b/service/sns/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sns/generated.json b/service/sns/generated.json index d5bf839eae9..6efa176328e 100644 --- a/service/sns/generated.json +++ b/service/sns/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sns/go.mod b/service/sns/go.mod index 64579ea56bc..4ee64db4f93 100644 --- a/service/sns/go.mod +++ b/service/sns/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sns/internal/endpoints/endpoints.go b/service/sns/internal/endpoints/endpoints.go index 20b6e8614c5..149275c00de 100644 --- a/service/sns/internal/endpoints/endpoints.go +++ b/service/sns/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SNS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,296 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sns.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sns.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sns-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sns.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "sns-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "sns-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "sns-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "sns-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sns.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sns.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sns-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sns.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sns.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sns.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sns.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sns.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sns.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sns.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sns-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sns-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sns.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "sns.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "sns.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, CredentialScope: endpoints.CredentialScope{ diff --git a/service/sqs/api_client.go b/service/sqs/api_client.go index 6a1eafc0f67..14ea3feb2cd 100644 --- a/service/sqs/api_client.go +++ b/service/sqs/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sqs/endpoints.go b/service/sqs/endpoints.go index c9180f138f7..2e74d231a6c 100644 --- a/service/sqs/endpoints.go +++ b/service/sqs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sqs/generated.json b/service/sqs/generated.json index 93ebbb4cbf1..ea12abbfadf 100644 --- a/service/sqs/generated.json +++ b/service/sqs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sqs/go.mod b/service/sqs/go.mod index 994e49e04ad..a805b048b13 100644 --- a/service/sqs/go.mod +++ b/service/sqs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sqs/internal/endpoints/endpoints.go b/service/sqs/internal/endpoints/endpoints.go index a046b403f75..13fd4324ff3 100644 --- a/service/sqs/internal/endpoints/endpoints.go +++ b/service/sqs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SQS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,121 +102,296 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sqs.{region}.amazonaws.com", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sqs.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sqs-fips.{region}.api.aws", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sqs.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "sqs-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "sqs-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "sqs-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "sqs-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sqs.{region}.amazonaws.com.cn", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sqs.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sqs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sqs.{region}.amazonaws.com.cn", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sqs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sqs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{ Protocols: []string{"http", "https"}, }, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sqs.{region}.sc2s.sgov.gov", - Protocols: []string{"http", "https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sqs.{region}.sc2s.sgov.gov", + Protocols: []string{"http", "https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sqs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sqs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sqs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sqs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sqs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "sqs.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "sqs.us-gov-west-1.amazonaws.com", Protocols: []string{"http", "https"}, CredentialScope: endpoints.CredentialScope{ diff --git a/service/ssm/api_client.go b/service/ssm/api_client.go index 0660d9db08d..3c2488d256d 100644 --- a/service/ssm/api_client.go +++ b/service/ssm/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/ssm/endpoints.go b/service/ssm/endpoints.go index ab4433edc49..9a3779d20f2 100644 --- a/service/ssm/endpoints.go +++ b/service/ssm/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ssm/generated.json b/service/ssm/generated.json index 1faa87f195a..1266d956bed 100644 --- a/service/ssm/generated.json +++ b/service/ssm/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/ssm/go.mod b/service/ssm/go.mod index f3f67fe3211..b5bf3ad9ff5 100644 --- a/service/ssm/go.mod +++ b/service/ssm/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ssm/internal/endpoints/endpoints.go b/service/ssm/internal/endpoints/endpoints.go index 24c48ade116..6d13cbc3c36 100644 --- a/service/ssm/internal/endpoints/endpoints.go +++ b/service/ssm/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSM endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,131 +102,331 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ssm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "ssm-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "ssm-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "ssm-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "ssm-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "ssm-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ssm.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ssm.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ssm.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ssm.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "ssm.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "ssm.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/ssmcontacts/api_client.go b/service/ssmcontacts/api_client.go index 72aaf7f16bf..d4946c05f78 100644 --- a/service/ssmcontacts/api_client.go +++ b/service/ssmcontacts/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/ssmcontacts/endpoints.go b/service/ssmcontacts/endpoints.go index 3ffb4ae13cd..a298f728995 100644 --- a/service/ssmcontacts/endpoints.go +++ b/service/ssmcontacts/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ssmcontacts/generated.json b/service/ssmcontacts/generated.json index 31c7940bd60..b52fe1e4a27 100644 --- a/service/ssmcontacts/generated.json +++ b/service/ssmcontacts/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ssmcontacts/go.mod b/service/ssmcontacts/go.mod index a5a499d4db4..1ca04ae9381 100644 --- a/service/ssmcontacts/go.mod +++ b/service/ssmcontacts/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ssmcontacts/internal/endpoints/endpoints.go b/service/ssmcontacts/internal/endpoints/endpoints.go index 494c0809622..b4a8fcb1853 100644 --- a/service/ssmcontacts/internal/endpoints/endpoints.go +++ b/service/ssmcontacts/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSM Contacts endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-contacts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-contacts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-contacts.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-contacts.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-contacts.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm-contacts.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-contacts.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm-contacts.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-contacts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-contacts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-contacts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/ssmincidents/api_client.go b/service/ssmincidents/api_client.go index a23bfd00231..d7d436e2b6e 100644 --- a/service/ssmincidents/api_client.go +++ b/service/ssmincidents/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/ssmincidents/endpoints.go b/service/ssmincidents/endpoints.go index 3fe96d7d623..0355f2707a2 100644 --- a/service/ssmincidents/endpoints.go +++ b/service/ssmincidents/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ssmincidents/generated.json b/service/ssmincidents/generated.json index 17ba1f63701..f7dd9f0c77e 100644 --- a/service/ssmincidents/generated.json +++ b/service/ssmincidents/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0", "github.com/jmespath/go-jmespath": "v0.4.0" }, diff --git a/service/ssmincidents/go.mod b/service/ssmincidents/go.mod index df9bb1370c3..8a598617cdb 100644 --- a/service/ssmincidents/go.mod +++ b/service/ssmincidents/go.mod @@ -4,8 +4,14 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 github.com/jmespath/go-jmespath v0.4.0 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ssmincidents/internal/endpoints/endpoints.go b/service/ssmincidents/internal/endpoints/endpoints.go index 3696016c9be..2f63d9b78dd 100644 --- a/service/ssmincidents/internal/endpoints/endpoints.go +++ b/service/ssmincidents/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSM Incidents endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,61 +102,162 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-incidents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-incidents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-incidents.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-incidents.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-incidents.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm-incidents.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-incidents.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ssm-incidents.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ssm-incidents.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ssm-incidents-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ssm-incidents.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/sso/api_client.go b/service/sso/api_client.go index 8f70d4706b2..bd5039590ad 100644 --- a/service/sso/api_client.go +++ b/service/sso/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sso/endpoints.go b/service/sso/endpoints.go index 761a3a792cb..43c06f11afe 100644 --- a/service/sso/endpoints.go +++ b/service/sso/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sso/generated.json b/service/sso/generated.json index a82f11041b7..912295209c5 100644 --- a/service/sso/generated.json +++ b/service/sso/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/sso/go.mod b/service/sso/go.mod index 38a18b92a16..c455872c51c 100644 --- a/service/sso/go.mod +++ b/service/sso/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/sso/internal/endpoints/endpoints.go b/service/sso/internal/endpoints/endpoints.go index 398f8bc96aa..ea2fbf8ba3e 100644 --- a/service/sso/internal/endpoints/endpoints.go +++ b/service/sso/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSO endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,63 +102,154 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "portal.sso.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "portal.sso.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "portal.sso-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "portal.sso-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "portal.sso.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ + Hostname: "portal.sso.ap-northeast-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ + Hostname: "portal.sso.ap-northeast-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ + Hostname: "portal.sso.ap-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "portal.sso.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "portal.sso.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Hostname: "portal.sso.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "portal.sso.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ + Hostname: "portal.sso.eu-north-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "portal.sso.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "portal.sso.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ + Hostname: "portal.sso.eu-west-3.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-3", + }, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ + Hostname: "portal.sso.sa-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "sa-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "portal.sso.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "portal.sso.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "portal.sso.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", @@ -121,42 +259,110 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "portal.sso.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "portal.sso.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "portal.sso-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "portal.sso-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "portal.sso.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "portal.sso.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "portal.sso.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "portal.sso.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "portal.sso.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "portal.sso.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "portal.sso.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "portal.sso-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "portal.sso-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "portal.sso.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + Hostname: "portal.sso.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + }, }, } diff --git a/service/ssoadmin/api_client.go b/service/ssoadmin/api_client.go index 1553dfd47c2..d92ede78640 100644 --- a/service/ssoadmin/api_client.go +++ b/service/ssoadmin/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ssoadmin/endpoints.go b/service/ssoadmin/endpoints.go index 8e8cc41fc18..e5f784928be 100644 --- a/service/ssoadmin/endpoints.go +++ b/service/ssoadmin/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ssoadmin/generated.json b/service/ssoadmin/generated.json index 8ddd61a9bd1..9e3d0a371b5 100644 --- a/service/ssoadmin/generated.json +++ b/service/ssoadmin/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ssoadmin/go.mod b/service/ssoadmin/go.mod index 1b787ee4433..e228d8c53a7 100644 --- a/service/ssoadmin/go.mod +++ b/service/ssoadmin/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ssoadmin/internal/endpoints/endpoints.go b/service/ssoadmin/internal/endpoints/endpoints.go index e067a94dd6b..8a559c05c42 100644 --- a/service/ssoadmin/internal/endpoints/endpoints.go +++ b/service/ssoadmin/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSO Admin endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sso.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sso.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sso-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sso-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sso.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sso.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sso.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sso-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sso-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sso.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sso.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sso.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sso.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sso.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sso.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sso.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sso-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sso-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sso.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/ssooidc/api_client.go b/service/ssooidc/api_client.go index 1732f7a83c7..0bfae13885e 100644 --- a/service/ssooidc/api_client.go +++ b/service/ssooidc/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/ssooidc/endpoints.go b/service/ssooidc/endpoints.go index fdd9386413a..35cd21f18c9 100644 --- a/service/ssooidc/endpoints.go +++ b/service/ssooidc/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/ssooidc/generated.json b/service/ssooidc/generated.json index af45587a4dd..696667745c1 100644 --- a/service/ssooidc/generated.json +++ b/service/ssooidc/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/ssooidc/go.mod b/service/ssooidc/go.mod index 01de9b792ef..0e4b8c88668 100644 --- a/service/ssooidc/go.mod +++ b/service/ssooidc/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/ssooidc/internal/endpoints/endpoints.go b/service/ssooidc/internal/endpoints/endpoints.go index bed90c5e37c..e345fab3388 100644 --- a/service/ssooidc/internal/endpoints/endpoints.go +++ b/service/ssooidc/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SSO OIDC endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,99 +102,154 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "oidc.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "oidc.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "oidc-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "oidc-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "oidc.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "oidc.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "oidc.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, }, - "ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ Hostname: "oidc.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "oidc.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "oidc.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Hostname: "oidc.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "oidc.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ Hostname: "oidc.eu-north-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "oidc.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "oidc.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ Hostname: "oidc.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "oidc.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "oidc.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "oidc.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "oidc.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", @@ -157,45 +259,105 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "oidc.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "oidc.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "oidc-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "oidc-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "oidc.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "oidc.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "oidc.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "oidc.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "oidc.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "oidc.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "oidc.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "oidc-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "oidc-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "oidc.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "oidc.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/storagegateway/api_client.go b/service/storagegateway/api_client.go index b5bf34686c4..0cb7764e8c8 100644 --- a/service/storagegateway/api_client.go +++ b/service/storagegateway/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/storagegateway/endpoints.go b/service/storagegateway/endpoints.go index b5fa037e764..3d1020406de 100644 --- a/service/storagegateway/endpoints.go +++ b/service/storagegateway/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/storagegateway/generated.json b/service/storagegateway/generated.json index bf48871f5e7..751c5fc1ec1 100644 --- a/service/storagegateway/generated.json +++ b/service/storagegateway/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/storagegateway/go.mod b/service/storagegateway/go.mod index b0c3d276822..e47ffedd80c 100644 --- a/service/storagegateway/go.mod +++ b/service/storagegateway/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/storagegateway/internal/endpoints/endpoints.go b/service/storagegateway/internal/endpoints/endpoints.go index a456fd142ed..52f670d2114 100644 --- a/service/storagegateway/internal/endpoints/endpoints.go +++ b/service/storagegateway/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Storage Gateway endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,95 +102,232 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "storagegateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "storagegateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "storagegateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "storagegateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "storagegateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "storagegateway-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "storagegateway.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "storagegateway.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "storagegateway-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "storagegateway-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "storagegateway.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "storagegateway.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "storagegateway.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "storagegateway.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "storagegateway.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "storagegateway.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "storagegateway.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "storagegateway-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "storagegateway-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "storagegateway.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips", + }: endpoints.Endpoint{ Hostname: "storagegateway-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, }, }, } diff --git a/service/sts/api_client.go b/service/sts/api_client.go index 339254f934a..1c022f9907e 100644 --- a/service/sts/api_client.go +++ b/service/sts/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" @@ -127,6 +128,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -176,6 +179,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -204,7 +209,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -246,6 +251,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/sts/endpoints.go b/service/sts/endpoints.go index 5b6aa7b1771..cababea22d9 100644 --- a/service/sts/endpoints.go +++ b/service/sts/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/sts/generated.json b/service/sts/generated.json index d223a42ed7f..9aca91bc3eb 100644 --- a/service/sts/generated.json +++ b/service/sts/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7", "github.com/aws/smithy-go": "v1.4.0" }, diff --git a/service/sts/go.mod b/service/sts/go.mod index c6b11886031..6be812aca7d 100644 --- a/service/sts/go.mod +++ b/service/sts/go.mod @@ -4,10 +4,16 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.4.0 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ diff --git a/service/sts/internal/endpoints/endpoints.go b/service/sts/internal/endpoints/endpoints.go index e68b7cb3e55..5075f6426c9 100644 --- a/service/sts/internal/endpoints/endpoints.go +++ b/service/sts/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver STS endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,131 +102,326 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "sts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "sts.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "sts-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "sts-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1-fips", + }: endpoints.Endpoint{ Hostname: "sts-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "sts-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "sts.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sts.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sts-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sts.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "sts.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sts.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "sts.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "sts.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "sts.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "sts.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "sts-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "sts.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1-fips", + }: endpoints.Endpoint{ Hostname: "sts.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "sts.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "sts.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/support/api_client.go b/service/support/api_client.go index 5a88e74856b..b52ed637b39 100644 --- a/service/support/api_client.go +++ b/service/support/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/support/endpoints.go b/service/support/endpoints.go index b9b9632f255..fb38121cd86 100644 --- a/service/support/endpoints.go +++ b/service/support/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/support/generated.json b/service/support/generated.json index 354bd91e80e..c6b6f17b0ca 100644 --- a/service/support/generated.json +++ b/service/support/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/support/go.mod b/service/support/go.mod index bb6a262aa6b..a2822a511a7 100644 --- a/service/support/go.mod +++ b/service/support/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/support/internal/endpoints/endpoints.go b/service/support/internal/endpoints/endpoints.go index abf6d4c1969..2c192d653bf 100644 --- a/service/support/internal/endpoints/endpoints.go +++ b/service/support/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Support endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,15 +102,42 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "support.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "support.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "support-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "support-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "support.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "support.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -73,15 +147,42 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "support.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "support.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "support-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "support-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "support.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-cn-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-cn-global", + }: endpoints.Endpoint{ Hostname: "support.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", @@ -91,15 +192,21 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "support.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "support.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-iso-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-global", + }: endpoints.Endpoint{ Hostname: "support.us-iso-east-1.c2s.ic.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-iso-east-1", @@ -109,15 +216,21 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "support.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "support.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-iso-b-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-iso-b-global", + }: endpoints.Endpoint{ Hostname: "support.us-isob-east-1.sc2s.sgov.gov", CredentialScope: endpoints.CredentialScope{ Region: "us-isob-east-1", @@ -127,25 +240,73 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "support.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "support.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "support-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "support-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "support.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "aws-us-gov-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-us-gov-global", + }: endpoints.Endpoint{ + Hostname: "support.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "support.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { Hostname: "support.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/swf/api_client.go b/service/swf/api_client.go index df34eae0563..53eb252efd4 100644 --- a/service/swf/api_client.go +++ b/service/swf/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/swf/endpoints.go b/service/swf/endpoints.go index a4ec5c2c69b..bd48ff1d8f2 100644 --- a/service/swf/endpoints.go +++ b/service/swf/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/swf/generated.json b/service/swf/generated.json index 2aafeff9831..1fbdab5b718 100644 --- a/service/swf/generated.json +++ b/service/swf/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/swf/go.mod b/service/swf/go.mod index e8172441064..093f5829b10 100644 --- a/service/swf/go.mod +++ b/service/swf/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/swf/internal/endpoints/endpoints.go b/service/swf/internal/endpoints/endpoints.go index 3471ede430f..61a6232f597 100644 --- a/service/swf/internal/endpoints/endpoints.go +++ b/service/swf/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver SWF endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,294 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "swf.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "swf.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "swf-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "swf.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "swf-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "swf-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "swf-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "swf-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "swf.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "swf.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "swf-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "swf.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "swf.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "swf.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, - "us-iso-west-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-west-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "swf.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "swf.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-isob-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "swf.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "swf.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "swf-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "swf-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "swf.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "swf.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "swf.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", diff --git a/service/synthetics/api_client.go b/service/synthetics/api_client.go index fc5f2a7d92c..b4e9a284cf5 100644 --- a/service/synthetics/api_client.go +++ b/service/synthetics/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/synthetics/endpoints.go b/service/synthetics/endpoints.go index 6f545fc8542..5f834c97958 100644 --- a/service/synthetics/endpoints.go +++ b/service/synthetics/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/synthetics/generated.json b/service/synthetics/generated.json index 50cef98d7cf..d4021bbf1cb 100644 --- a/service/synthetics/generated.json +++ b/service/synthetics/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/synthetics/go.mod b/service/synthetics/go.mod index f91065ca00e..7a307c83c42 100644 --- a/service/synthetics/go.mod +++ b/service/synthetics/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/synthetics/internal/endpoints/endpoints.go b/service/synthetics/internal/endpoints/endpoints.go index d8d44fbeb5c..8a4fac886a8 100644 --- a/service/synthetics/internal/endpoints/endpoints.go +++ b/service/synthetics/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver synthetics endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,52 +102,226 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "synthetics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "synthetics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "synthetics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "synthetics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "synthetics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "synthetics.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "synthetics.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "synthetics-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "synthetics-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "synthetics.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "synthetics.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "synthetics.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "synthetics.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "synthetics.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-isob-east-1", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "synthetics.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "synthetics.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "synthetics-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "synthetics-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "synthetics.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + }, }, } diff --git a/service/textract/api_client.go b/service/textract/api_client.go index e969e403362..5dd2eb7ddcb 100644 --- a/service/textract/api_client.go +++ b/service/textract/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/textract/endpoints.go b/service/textract/endpoints.go index 40b466972ec..49ada8acbf8 100644 --- a/service/textract/endpoints.go +++ b/service/textract/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/textract/generated.json b/service/textract/generated.json index 38c006b3b06..216210aaa0a 100644 --- a/service/textract/generated.json +++ b/service/textract/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/textract/go.mod b/service/textract/go.mod index ffadd78615b..f8a2df3a659 100644 --- a/service/textract/go.mod +++ b/service/textract/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/textract/internal/endpoints/endpoints.go b/service/textract/internal/endpoints/endpoints.go index b36356c9a29..727757993fe 100644 --- a/service/textract/internal/endpoints/endpoints.go +++ b/service/textract/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Textract endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,113 +102,289 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "textract.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "textract.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "textract-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "textract.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "textract-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "textract.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "textract.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "textract-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "textract.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "textract.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "textract.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "textract.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "textract.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "textract.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "textract.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "textract-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "textract.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "textract-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "textract-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/timestreamquery/api_client.go b/service/timestreamquery/api_client.go index 00168689e4d..147c6bf0262 100644 --- a/service/timestreamquery/api_client.go +++ b/service/timestreamquery/api_client.go @@ -148,6 +148,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -198,6 +200,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -226,7 +230,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -290,6 +294,36 @@ func resolveEnableEndpointDiscoveryFromConfigSources(cfg aws.Config, o *Options) return nil } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // resolves endpoint cache on client func resolveEndpointCache(c *Client) { c.endpointCache = internalEndpointDiscovery.NewEndpointCache(10) diff --git a/service/timestreamquery/endpoints.go b/service/timestreamquery/endpoints.go index 94c2b7628a7..5c95e03d073 100644 --- a/service/timestreamquery/endpoints.go +++ b/service/timestreamquery/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/timestreamquery/generated.json b/service/timestreamquery/generated.json index 3b86f9b3e3a..658524ae211 100644 --- a/service/timestreamquery/generated.json +++ b/service/timestreamquery/generated.json @@ -2,6 +2,7 @@ "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery": "v0.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, diff --git a/service/timestreamquery/go.mod b/service/timestreamquery/go.mod index 634ce2c25e1..cf7419362bf 100644 --- a/service/timestreamquery/go.mod +++ b/service/timestreamquery/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.2.0 github.com/aws/smithy-go v1.8.1 ) @@ -13,4 +14,6 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ diff --git a/service/timestreamquery/internal/endpoints/endpoints.go b/service/timestreamquery/internal/endpoints/endpoints.go index 84df6bea531..b6814a1aeef 100644 --- a/service/timestreamquery/internal/endpoints/endpoints.go +++ b/service/timestreamquery/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Timestream Query endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "query.timestream.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "query.timestream.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "query.timestream-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "query.timestream-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "query.timestream.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "query.timestream.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "query.timestream.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "query.timestream-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "query.timestream-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "query.timestream.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "query.timestream.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "query.timestream.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "query.timestream.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "query.timestream.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "query.timestream.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "query.timestream.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "query.timestream-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "query.timestream-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "query.timestream.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/timestreamwrite/api_client.go b/service/timestreamwrite/api_client.go index 674e85dfaca..35543becfdc 100644 --- a/service/timestreamwrite/api_client.go +++ b/service/timestreamwrite/api_client.go @@ -140,6 +140,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -190,6 +192,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -218,7 +222,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -275,6 +279,36 @@ func resolveEnableEndpointDiscoveryFromConfigSources(cfg aws.Config, o *Options) return nil } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // resolves endpoint cache on client func resolveEndpointCache(c *Client) { c.endpointCache = internalEndpointDiscovery.NewEndpointCache(10) diff --git a/service/timestreamwrite/endpoints.go b/service/timestreamwrite/endpoints.go index 6467637e677..17f1b4e591b 100644 --- a/service/timestreamwrite/endpoints.go +++ b/service/timestreamwrite/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/timestreamwrite/generated.json b/service/timestreamwrite/generated.json index 2b2843bf563..3d8a8e853ce 100644 --- a/service/timestreamwrite/generated.json +++ b/service/timestreamwrite/generated.json @@ -2,6 +2,7 @@ "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery": "v0.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, diff --git a/service/timestreamwrite/go.mod b/service/timestreamwrite/go.mod index abfeb7b03ea..9283584fb90 100644 --- a/service/timestreamwrite/go.mod +++ b/service/timestreamwrite/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.2.0 github.com/aws/smithy-go v1.8.1 ) @@ -13,4 +14,6 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ diff --git a/service/timestreamwrite/internal/endpoints/endpoints.go b/service/timestreamwrite/internal/endpoints/endpoints.go index baf7927a44f..ea95cb84944 100644 --- a/service/timestreamwrite/internal/endpoints/endpoints.go +++ b/service/timestreamwrite/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Timestream Write endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "ingest.timestream.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ingest.timestream.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "ingest.timestream.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ingest.timestream.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "ingest.timestream.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ingest.timestream.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "ingest.timestream.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "ingest.timestream.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "ingest.timestream.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "ingest.timestream-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "ingest.timestream.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/transcribe/api_client.go b/service/transcribe/api_client.go index b6979f8a36d..d07ade077fd 100644 --- a/service/transcribe/api_client.go +++ b/service/transcribe/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/transcribe/endpoints.go b/service/transcribe/endpoints.go index 83971161d32..bbffd5cb81c 100644 --- a/service/transcribe/endpoints.go +++ b/service/transcribe/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/transcribe/generated.json b/service/transcribe/generated.json index 1626bc079d3..27c23e662dc 100644 --- a/service/transcribe/generated.json +++ b/service/transcribe/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/transcribe/go.mod b/service/transcribe/go.mod index 15ddf4d8d96..32b97cb0082 100644 --- a/service/transcribe/go.mod +++ b/service/transcribe/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/transcribe/internal/endpoints/endpoints.go b/service/transcribe/internal/endpoints/endpoints.go index 69edd845334..7066f0cd57d 100644 --- a/service/transcribe/internal/endpoints/endpoints.go +++ b/service/transcribe/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Transcribe endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,74 +102,198 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "transcribe.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transcribe.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transcribe-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transcribe-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transcribe.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "transcribe.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transcribe.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transcribe-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transcribe-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transcribe.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ Hostname: "cn.transcribe.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, }, - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "cn.transcribe.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", @@ -132,51 +303,108 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "transcribe.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "transcribe.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "transcribe.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "transcribe.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "transcribe.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transcribe.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transcribe-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transcribe-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transcribe.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "fips.transcribe.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "fips.transcribe.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/transfer/api_client.go b/service/transfer/api_client.go index 9d38d8984d1..4466927d24e 100644 --- a/service/transfer/api_client.go +++ b/service/transfer/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/transfer/endpoints.go b/service/transfer/endpoints.go index 2fec3086a8e..a2500310b86 100644 --- a/service/transfer/endpoints.go +++ b/service/transfer/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/transfer/generated.json b/service/transfer/generated.json index 58dae2d9556..fdd46005a73 100644 --- a/service/transfer/generated.json +++ b/service/transfer/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/transfer/go.mod b/service/transfer/go.mod index d770d598ca5..e7c2be76ac6 100644 --- a/service/transfer/go.mod +++ b/service/transfer/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/transfer/internal/endpoints/endpoints.go b/service/transfer/internal/endpoints/endpoints.go index 4fb868505d1..96045a55c7f 100644 --- a/service/transfer/internal/endpoints/endpoints.go +++ b/service/transfer/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Transfer endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,124 +102,318 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "transfer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transfer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transfer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transfer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.ca-central-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "transfer-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "transfer.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transfer.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transfer-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transfer.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "transfer.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "transfer.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "transfer.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "transfer.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "transfer.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "transfer.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "transfer-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "transfer.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "transfer-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "transfer-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/translate/api_client.go b/service/translate/api_client.go index c34a352c595..c0a60882948 100644 --- a/service/translate/api_client.go +++ b/service/translate/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/translate/endpoints.go b/service/translate/endpoints.go index 37fd8fee7c9..e6b16706882 100644 --- a/service/translate/endpoints.go +++ b/service/translate/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/translate/generated.json b/service/translate/generated.json index 0a0bd528ac5..2ed42d21d66 100644 --- a/service/translate/generated.json +++ b/service/translate/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/translate/go.mod b/service/translate/go.mod index d4a755a7f68..954d3f99478 100644 --- a/service/translate/go.mod +++ b/service/translate/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/translate/internal/endpoints/endpoints.go b/service/translate/internal/endpoints/endpoints.go index c034489b92e..b3c1d29b0ce 100644 --- a/service/translate/internal/endpoints/endpoints.go +++ b/service/translate/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Translate endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,99 +102,254 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "translate.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "translate.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "translate-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "translate.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-1-fips", + }: endpoints.Endpoint{ Hostname: "translate-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.us-east-2.amazonaws.com", }, - "us-east-2": endpoints.Endpoint{}, - "us-east-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2-fips", + }: endpoints.Endpoint{ Hostname: "translate-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, - "us-west-2-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.us-west-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2-fips", + }: endpoints.Endpoint{ Hostname: "translate-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "translate.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "translate.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "translate-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "translate.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "translate.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "translate.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "translate.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "translate.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "translate.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "translate.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "translate-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "translate.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-gov-west-1": endpoints.Endpoint{}, - "us-gov-west-1-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "translate-fips.us-gov-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1-fips", + }: endpoints.Endpoint{ Hostname: "translate-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, }, }, diff --git a/service/voiceid/api_client.go b/service/voiceid/api_client.go index f248c679a17..e2528873ca6 100644 --- a/service/voiceid/api_client.go +++ b/service/voiceid/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/voiceid/endpoints.go b/service/voiceid/endpoints.go index b684c86d890..b40aae212b6 100644 --- a/service/voiceid/endpoints.go +++ b/service/voiceid/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/voiceid/generated.json b/service/voiceid/generated.json index f236e4c633a..e46d853c60d 100644 --- a/service/voiceid/generated.json +++ b/service/voiceid/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/voiceid/go.mod b/service/voiceid/go.mod index da0eb21e210..5beca187ea4 100644 --- a/service/voiceid/go.mod +++ b/service/voiceid/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/voiceid/internal/endpoints/endpoints.go b/service/voiceid/internal/endpoints/endpoints.go index 753279d6e8f..3af2d35e27c 100644 --- a/service/voiceid/internal/endpoints/endpoints.go +++ b/service/voiceid/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Voice ID endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,59 +102,156 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "voiceid.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "voiceid.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "voiceid-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "voiceid-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "voiceid.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "voiceid.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "voiceid.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "voiceid-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "voiceid-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "voiceid.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "voiceid.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "voiceid.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "voiceid.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "voiceid.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "voiceid.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "voiceid.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "voiceid-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "voiceid-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "voiceid.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/waf/api_client.go b/service/waf/api_client.go index ecb7e803858..078af807d9e 100644 --- a/service/waf/api_client.go +++ b/service/waf/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/waf/endpoints.go b/service/waf/endpoints.go index 34665df0ee6..8363d51cd61 100644 --- a/service/waf/endpoints.go +++ b/service/waf/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/waf/generated.json b/service/waf/generated.json index 35e9e49c44c..ff5deeea73c 100644 --- a/service/waf/generated.json +++ b/service/waf/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/waf/go.mod b/service/waf/go.mod index 36807e83a54..076fe435f65 100644 --- a/service/waf/go.mod +++ b/service/waf/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/waf/internal/endpoints/endpoints.go b/service/waf/internal/endpoints/endpoints.go index 1f15710743e..557d979bab8 100644 --- a/service/waf/internal/endpoints/endpoints.go +++ b/service/waf/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WAF endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,22 +102,70 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "waf.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: false, PartitionEndpoint: "aws-global", Endpoints: endpoints.Endpoints{ - "aws-fips": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws", + }: endpoints.Endpoint{ + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "aws", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-fips.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "aws-fips", + }: endpoints.Endpoint{ Hostname: "waf-fips.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "aws-global": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "aws-global", + }: endpoints.Endpoint{ Hostname: "waf.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", @@ -80,40 +175,98 @@ var defaultPartitions = endpoints.Partitions{ }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "waf.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "waf.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "waf.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "waf.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "waf.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "waf.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/wafregional/api_client.go b/service/wafregional/api_client.go index f0e2307d676..cbd166cc242 100644 --- a/service/wafregional/api_client.go +++ b/service/wafregional/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/wafregional/endpoints.go b/service/wafregional/endpoints.go index f299829f083..30d4acb87e8 100644 --- a/service/wafregional/endpoints.go +++ b/service/wafregional/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/wafregional/generated.json b/service/wafregional/generated.json index fc1e8c79bc8..305c3cdf16b 100644 --- a/service/wafregional/generated.json +++ b/service/wafregional/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/wafregional/go.mod b/service/wafregional/go.mod index 438227604d7..5c6d536c451 100644 --- a/service/wafregional/go.mod +++ b/service/wafregional/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/wafregional/internal/endpoints/endpoints.go b/service/wafregional/internal/endpoints/endpoints.go index 9bfae9232be..a523e37944c 100644 --- a/service/wafregional/internal/endpoints/endpoints.go +++ b/service/wafregional/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WAF Regional endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,358 +102,791 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "waf-regional.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf-regional.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-regional-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf-regional.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.af-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "af-south-1", }, }, - "ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.af-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "af-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-east-1", }, }, - "ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, }, - "ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-northeast-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, }, - "ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-northeast-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-northeast-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, }, - "ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-northeast-3.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-northeast-3", + }, + }, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, }, - "ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, }, - "ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-southeast-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-1", + }, + }, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "waf-regional.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, }, - "ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-southeast-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ap-southeast-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ap-southeast-2", + }, + }, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, }, - "eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ca-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.ca-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "ca-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, }, - "eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-central-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-central-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-central-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-north-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, }, - "eu-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-north-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-north-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-south-1", }, }, - "eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, }, - "eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, }, - "eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-2", + }, + }, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{ Hostname: "waf-regional.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, }, - "fips-af-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "eu-west-3", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.eu-west-3.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "eu-west-3", + }, + }, + endpoints.EndpointKey{ + Region: "fips-af-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.af-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "af-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-northeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-2", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-northeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-northeast-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-northeast-3", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-northeast-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-northeast-3", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-southeast-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-1", }, + Deprecated: aws.TrueTernary, }, - "fips-ap-southeast-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ap-southeast-2", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ap-southeast-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ap-southeast-2", }, + Deprecated: aws.TrueTernary, }, - "fips-ca-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-ca-central-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.ca-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "ca-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-central-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-central-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-central-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-central-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-north-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-north-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-north-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-2", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-2", }, + Deprecated: aws.TrueTernary, }, - "fips-eu-west-3": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-eu-west-3", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.eu-west-3.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "eu-west-3", }, + Deprecated: aws.TrueTernary, }, - "fips-me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-me-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.me-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "me-south-1", }, + Deprecated: aws.TrueTernary, }, - "fips-sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-sa-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, }, - "me-south-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.me-south-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "me-south-1", }, }, - "sa-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "me-south-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.me-south-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "me-south-1", + }, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.sa-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "sa-east-1", }, }, - "us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "sa-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.sa-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "sa-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, }, - "us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, }, - "us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-east-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-east-2", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, }, - "us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, }, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-west-2.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-west-2", + }, + }, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "waf-regional.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf-regional.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-regional-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf-regional.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, }, - "cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-north-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.cn-north-1.amazonaws.com.cn", + CredentialScope: endpoints.CredentialScope{ + Region: "cn-north-1", + }, + }, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", }, }, - "fips-cn-north-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "cn-northwest-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.cn-northwest-1.amazonaws.com.cn", + CredentialScope: endpoints.CredentialScope{ + Region: "cn-northwest-1", + }, + }, + endpoints.EndpointKey{ + Region: "fips-cn-north-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.cn-north-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-north-1", }, + Deprecated: aws.TrueTernary, }, - "fips-cn-northwest-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-cn-northwest-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.cn-northwest-1.amazonaws.com.cn", CredentialScope: endpoints.CredentialScope{ Region: "cn-northwest-1", }, + Deprecated: aws.TrueTernary, }, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "waf-regional.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "waf-regional.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "waf-regional.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "waf-regional.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "waf-regional.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "waf-regional.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "waf-regional-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "waf-regional.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, }, - "us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, }, - "us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-gov-east-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-east-1", + }, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "waf-regional.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "waf-regional-fips.us-gov-west-1.amazonaws.com", + CredentialScope: endpoints.CredentialScope{ + Region: "us-gov-west-1", + }, + }, }, }, } diff --git a/service/wafv2/api_client.go b/service/wafv2/api_client.go index 7c0786ff150..11a7986f8ce 100644 --- a/service/wafv2/api_client.go +++ b/service/wafv2/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/wafv2/endpoints.go b/service/wafv2/endpoints.go index 35aa3033428..f2260574b63 100644 --- a/service/wafv2/endpoints.go +++ b/service/wafv2/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/wafv2/generated.json b/service/wafv2/generated.json index f51902c80c7..33a8b9b1236 100644 --- a/service/wafv2/generated.json +++ b/service/wafv2/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/wafv2/go.mod b/service/wafv2/go.mod index cfb6bf2dc6d..b1b9022d96b 100644 --- a/service/wafv2/go.mod +++ b/service/wafv2/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/wafv2/internal/endpoints/endpoints.go b/service/wafv2/internal/endpoints/endpoints.go index 8a0648efbbb..ce406dc502f 100644 --- a/service/wafv2/internal/endpoints/endpoints.go +++ b/service/wafv2/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WAFV2 endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "wafv2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wafv2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wafv2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wafv2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wafv2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "wafv2.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wafv2.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wafv2-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wafv2-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wafv2.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "wafv2.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wafv2.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "wafv2.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wafv2.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "wafv2.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wafv2.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wafv2-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wafv2-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wafv2.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/wellarchitected/api_client.go b/service/wellarchitected/api_client.go index 37f46cd2776..61dfe007faa 100644 --- a/service/wellarchitected/api_client.go +++ b/service/wellarchitected/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -133,6 +134,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -182,6 +185,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -210,7 +215,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -259,6 +264,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/wellarchitected/endpoints.go b/service/wellarchitected/endpoints.go index ac021e89608..7902782163c 100644 --- a/service/wellarchitected/endpoints.go +++ b/service/wellarchitected/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/wellarchitected/generated.json b/service/wellarchitected/generated.json index ff0147239b8..ea25985d4d7 100644 --- a/service/wellarchitected/generated.json +++ b/service/wellarchitected/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/wellarchitected/go.mod b/service/wellarchitected/go.mod index 4e20c39ee90..a16d820535c 100644 --- a/service/wellarchitected/go.mod +++ b/service/wellarchitected/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/wellarchitected/internal/endpoints/endpoints.go b/service/wellarchitected/internal/endpoints/endpoints.go index 4412ee761f4..ce0d0b51dde 100644 --- a/service/wellarchitected/internal/endpoints/endpoints.go +++ b/service/wellarchitected/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WellArchitected endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "wellarchitected.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wellarchitected-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wellarchitected.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "wellarchitected.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wellarchitected-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wellarchitected.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "wellarchitected.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wellarchitected.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "wellarchitected.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wellarchitected.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "wellarchitected.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wellarchitected-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wellarchitected-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wellarchitected.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/wisdom/api_client.go b/service/wisdom/api_client.go index 673349f4171..ed2d8f36a5a 100644 --- a/service/wisdom/api_client.go +++ b/service/wisdom/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/wisdom/endpoints.go b/service/wisdom/endpoints.go index 91a9bd9e95d..307bcf48bf0 100644 --- a/service/wisdom/endpoints.go +++ b/service/wisdom/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/wisdom/generated.json b/service/wisdom/generated.json index 909495a1e71..01a3086206c 100644 --- a/service/wisdom/generated.json +++ b/service/wisdom/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/wisdom/go.mod b/service/wisdom/go.mod index d4879020d2b..01689dc36f1 100644 --- a/service/wisdom/go.mod +++ b/service/wisdom/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/wisdom/internal/endpoints/endpoints.go b/service/wisdom/internal/endpoints/endpoints.go index c72ce0f3fcc..f2cf89d2061 100644 --- a/service/wisdom/internal/endpoints/endpoints.go +++ b/service/wisdom/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver Wisdom endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,153 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "wisdom.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wisdom.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wisdom-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wisdom-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wisdom.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, + Endpoints: endpoints.Endpoints{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "wisdom.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wisdom.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wisdom-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wisdom-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wisdom.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "wisdom.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wisdom.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "wisdom.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "wisdom.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "wisdom.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "wisdom.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "wisdom-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "wisdom-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "wisdom.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/workdocs/api_client.go b/service/workdocs/api_client.go index 3378f10e072..3f9346f96af 100644 --- a/service/workdocs/api_client.go +++ b/service/workdocs/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/workdocs/endpoints.go b/service/workdocs/endpoints.go index b6f14944a42..68ce4c09570 100644 --- a/service/workdocs/endpoints.go +++ b/service/workdocs/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/workdocs/generated.json b/service/workdocs/generated.json index 94c4d37b9e1..0de61afdbe8 100644 --- a/service/workdocs/generated.json +++ b/service/workdocs/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/workdocs/go.mod b/service/workdocs/go.mod index f5694b8223b..11cf17b748a 100644 --- a/service/workdocs/go.mod +++ b/service/workdocs/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/workdocs/internal/endpoints/endpoints.go b/service/workdocs/internal/endpoints/endpoints.go index 2630d84fa60..ce15299c575 100644 --- a/service/workdocs/internal/endpoints/endpoints.go +++ b/service/workdocs/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WorkDocs endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,70 +102,183 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "workdocs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workdocs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workdocs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workdocs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workdocs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "workdocs-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "workdocs-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workdocs-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workdocs-fips.us-west-2.amazonaws.com", }, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "workdocs.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workdocs.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workdocs-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workdocs-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workdocs.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "workdocs.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workdocs.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "workdocs.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workdocs.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "workdocs.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workdocs.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workdocs-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workdocs-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workdocs.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/worklink/api_client.go b/service/worklink/api_client.go index 6ff2d199037..988b01e86ee 100644 --- a/service/worklink/api_client.go +++ b/service/worklink/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/worklink/endpoints.go b/service/worklink/endpoints.go index b610aea3bc3..3d1b8b82e58 100644 --- a/service/worklink/endpoints.go +++ b/service/worklink/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/worklink/generated.json b/service/worklink/generated.json index 61131bf8e03..54ea8338844 100644 --- a/service/worklink/generated.json +++ b/service/worklink/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/worklink/go.mod b/service/worklink/go.mod index 6d6461da62c..cd7df0cbe05 100644 --- a/service/worklink/go.mod +++ b/service/worklink/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/worklink/internal/endpoints/endpoints.go b/service/worklink/internal/endpoints/endpoints.go index 0ed2cd6f0fa..f4ac90ec475 100644 --- a/service/worklink/internal/endpoints/endpoints.go +++ b/service/worklink/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WorkLink endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "worklink.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "worklink.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "worklink-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "worklink-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "worklink.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "worklink.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "worklink.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "worklink-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "worklink-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "worklink.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "worklink.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "worklink.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "worklink.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "worklink.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "worklink.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "worklink.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "worklink-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "worklink-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "worklink.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/workmail/api_client.go b/service/workmail/api_client.go index 977f6697c60..6eefeb83bd9 100644 --- a/service/workmail/api_client.go +++ b/service/workmail/api_client.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -132,6 +133,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -181,6 +184,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -209,7 +214,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -258,6 +263,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + // IdempotencyTokenProvider interface for providing idempotency token type IdempotencyTokenProvider interface { GetIdempotencyToken() (string, error) diff --git a/service/workmail/endpoints.go b/service/workmail/endpoints.go index 0f5e7acd689..9a4d3b58f25 100644 --- a/service/workmail/endpoints.go +++ b/service/workmail/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/workmail/generated.json b/service/workmail/generated.json index 10c04390273..645882243a8 100644 --- a/service/workmail/generated.json +++ b/service/workmail/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/workmail/go.mod b/service/workmail/go.mod index e1a274c1685..9d2842a1685 100644 --- a/service/workmail/go.mod +++ b/service/workmail/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/workmail/internal/endpoints/endpoints.go b/service/workmail/internal/endpoints/endpoints.go index 88dc477f0c3..bfa449e9bb2 100644 --- a/service/workmail/internal/endpoints/endpoints.go +++ b/service/workmail/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WorkMail endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,55 +102,144 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "workmail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "eu-west-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "workmail.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmail.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmail-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmail-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmail.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "workmail.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workmail.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "workmail.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workmail.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "workmail.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmail.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmail-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmail-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmail.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/workmailmessageflow/api_client.go b/service/workmailmessageflow/api_client.go index 926c80da3bf..acd6905e61a 100644 --- a/service/workmailmessageflow/api_client.go +++ b/service/workmailmessageflow/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -125,6 +126,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -174,6 +177,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -202,7 +207,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -244,6 +249,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/workmailmessageflow/endpoints.go b/service/workmailmessageflow/endpoints.go index 22fd055db50..f60c29271b5 100644 --- a/service/workmailmessageflow/endpoints.go +++ b/service/workmailmessageflow/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/workmailmessageflow/generated.json b/service/workmailmessageflow/generated.json index 7cfdefaef65..5fda6abdf6e 100644 --- a/service/workmailmessageflow/generated.json +++ b/service/workmailmessageflow/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/workmailmessageflow/go.mod b/service/workmailmessageflow/go.mod index 29ca15d5cb0..87e5f6ff668 100644 --- a/service/workmailmessageflow/go.mod +++ b/service/workmailmessageflow/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/workmailmessageflow/internal/endpoints/endpoints.go b/service/workmailmessageflow/internal/endpoints/endpoints.go index 6b6f5050d4c..66c1f1b9f62 100644 --- a/service/workmailmessageflow/internal/endpoints/endpoints.go +++ b/service/workmailmessageflow/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WorkMailMessageFlow endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,50 +102,133 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "workmailmessageflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmailmessageflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "workmailmessageflow.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmailmessageflow.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "workmailmessageflow.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workmailmessageflow.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "workmailmessageflow.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workmailmessageflow.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "workmailmessageflow.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workmailmessageflow-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workmailmessageflow.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, diff --git a/service/workspaces/api_client.go b/service/workspaces/api_client.go index b7808ce7b3a..e992f516964 100644 --- a/service/workspaces/api_client.go +++ b/service/workspaces/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/workspaces/endpoints.go b/service/workspaces/endpoints.go index 79f747fca22..dc950fe3330 100644 --- a/service/workspaces/endpoints.go +++ b/service/workspaces/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/workspaces/generated.json b/service/workspaces/generated.json index 6e9bffa46f5..05fb45abd5a 100644 --- a/service/workspaces/generated.json +++ b/service/workspaces/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/workspaces/go.mod b/service/workspaces/go.mod index 3b741687590..4496f6a7a9d 100644 --- a/service/workspaces/go.mod +++ b/service/workspaces/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/workspaces/internal/endpoints/endpoints.go b/service/workspaces/internal/endpoints/endpoints.go index 94d0b6fe413..91392bd0299 100644 --- a/service/workspaces/internal/endpoints/endpoints.go +++ b/service/workspaces/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver WorkSpaces endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,93 +102,233 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "workspaces.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workspaces.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workspaces-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workspaces.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "workspaces-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "workspaces-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.us-west-2.amazonaws.com", }, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "workspaces.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workspaces.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workspaces-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workspaces.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "workspaces.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workspaces.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "us-iso-east-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-iso-east-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "workspaces.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "workspaces.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "workspaces.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "workspaces.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "workspaces-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "workspaces.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "workspaces-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "workspaces-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-west-1": endpoints.Endpoint{}, }, }, } diff --git a/service/xray/api_client.go b/service/xray/api_client.go index 5f3d94b6423..237b95703b4 100644 --- a/service/xray/api_client.go +++ b/service/xray/api_client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" smithy "github.com/aws/smithy-go" smithydocument "github.com/aws/smithy-go/document" "github.com/aws/smithy-go/logging" @@ -124,6 +125,8 @@ func (c *Client) invokeOperation(ctx context.Context, opID string, params interf fn(&options) } + finalizeClientEndpointResolverOptions(&options) + for _, fn := range stackFns { if err := fn(stack, options); err != nil { return nil, metadata, err @@ -173,6 +176,8 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) + resolveUseDualStackEndpoint(cfg, &opts) + resolveUseFIPSEndpoint(cfg, &opts) return New(opts, optFns...) } @@ -201,7 +206,7 @@ func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { if cfg.EndpointResolver == nil { return } - o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) + o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) } func addClientUserAgent(stack *middleware.Stack) error { @@ -243,6 +248,36 @@ func addRetryMiddlewares(stack *middleware.Stack, o Options) error { return retry.AddRetryMiddlewares(stack, mo) } +// resolves dual-stack endpoint configuration +func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseDualStackEndpoint = value + } + return nil +} + +// resolves FIPS endpoint configuration +func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { + if len(cfg.ConfigSources) == 0 { + return nil + } + value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) + if err != nil { + return err + } + if found { + o.EndpointOptions.UseFIPSEndpoint = value + } + return nil +} + func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) } diff --git a/service/xray/endpoints.go b/service/xray/endpoints.go index 31d01bdc379..50e70ec4e7a 100644 --- a/service/xray/endpoints.go +++ b/service/xray/endpoints.go @@ -12,6 +12,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -87,8 +88,11 @@ func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.Ser return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil") } + eo := m.Options + eo.Logger = middleware.GetLogger(ctx) + var endpoint aws.Endpoint - endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), m.Options) + endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo) if err != nil { return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err) } @@ -124,7 +128,7 @@ func removeResolveEndpointMiddleware(stack *middleware.Stack) error { } type wrappedEndpointResolver struct { - awsResolver aws.EndpointResolver + awsResolver aws.EndpointResolverWithOptions resolver EndpointResolver } @@ -132,7 +136,7 @@ func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options Endpoin if w.awsResolver == nil { goto fallback } - endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region) + endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } @@ -148,13 +152,49 @@ fallback: return w.resolver.ResolveEndpoint(region, options) } -// withEndpointResolver returns an EndpointResolver that first delegates endpoint -// resolution to the awsResolver. If awsResolver returns aws.EndpointNotFoundError -// error, the resolver will use the the provided fallbackResolver for resolution. -// awsResolver and fallbackResolver must not be nil -func withEndpointResolver(awsResolver aws.EndpointResolver, fallbackResolver EndpointResolver) EndpointResolver { +type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error) + +func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { + return a(service, region) +} + +var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil) + +// withEndpointResolver returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. +// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided +// fallbackResolver for resolution. +// +// fallbackResolver must not be nil +func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions, fallbackResolver EndpointResolver) EndpointResolver { + var resolver aws.EndpointResolverWithOptions + + if awsResolverWithOptions != nil { + resolver = awsResolverWithOptions + } else if awsResolver != nil { + resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint) + } + return &wrappedEndpointResolver{ - awsResolver: awsResolver, + awsResolver: resolver, resolver: fallbackResolver, } } + +func finalizeClientEndpointResolverOptions(options *Options) { + options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage() + + if len(options.EndpointOptions.ResolvedRegion) == 0 { + const fipsInfix = "-fips-" + const fipsPrefix = "fips-" + const fipsSuffix = "-fips" + + if strings.Contains(options.Region, fipsInfix) || + strings.Contains(options.Region, fipsPrefix) || + strings.Contains(options.Region, fipsSuffix) { + options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "") + options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled + } + } + +} diff --git a/service/xray/generated.json b/service/xray/generated.json index fde6ca5f7b6..b4dc6890f45 100644 --- a/service/xray/generated.json +++ b/service/xray/generated.json @@ -1,6 +1,8 @@ { "dependencies": { "github.com/aws/aws-sdk-go-v2": "v1.4.0", + "github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000", + "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000", "github.com/aws/smithy-go": "v1.4.0" }, "files": [ diff --git a/service/xray/go.mod b/service/xray/go.mod index 18ffb179f0b..2f6f3b48f55 100644 --- a/service/xray/go.mod +++ b/service/xray/go.mod @@ -4,7 +4,13 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.10.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.7 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 github.com/aws/smithy-go v1.8.1 ) replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/xray/internal/endpoints/endpoints.go b/service/xray/internal/endpoints/endpoints.go index 1db09e625fa..9abdd795472 100644 --- a/service/xray/internal/endpoints/endpoints.go +++ b/service/xray/internal/endpoints/endpoints.go @@ -4,13 +4,62 @@ package endpoints import ( "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/internal/endpoints" + endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2" + "github.com/aws/smithy-go/logging" "regexp" ) // Options is the endpoint resolver configuration options type Options struct { + // Logger is a logging implementation that log events should be sent to. + Logger logging.Logger + + // LogDeprecated indicates that deprecated endpoints should be logged to the + // provided logger. + LogDeprecated bool + + // ResolvedRegion is used to override the region to be resolved, rather then the + // using the value passed to the ResolveEndpoint method. This value is used by the + // SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative + // name. You must not set this value directly in your application. + ResolvedRegion string + + // DisableHTTPS informs the resolver to return an endpoint that does not use the + // HTTPS scheme. DisableHTTPS bool + + // UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint. + UseDualStackEndpoint aws.DualStackEndpointState + + // UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint. + UseFIPSEndpoint aws.FIPSEndpointState +} + +func (o Options) GetResolvedRegion() string { + return o.ResolvedRegion +} + +func (o Options) GetDisableHTTPS() bool { + return o.DisableHTTPS +} + +func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState { + return o.UseDualStackEndpoint +} + +func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState { + return o.UseFIPSEndpoint +} + +func transformToSharedOptions(options Options) endpoints.Options { + return endpoints.Options{ + Logger: options.Logger, + LogDeprecated: options.LogDeprecated, + ResolvedRegion: options.ResolvedRegion, + DisableHTTPS: options.DisableHTTPS, + UseDualStackEndpoint: options.UseDualStackEndpoint, + UseFIPSEndpoint: options.UseFIPSEndpoint, + } } // Resolver XRay endpoint resolver @@ -24,9 +73,7 @@ func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws return endpoint, &aws.MissingRegionError{} } - opt := endpoints.Options{ - DisableHTTPS: options.DisableHTTPS, - } + opt := transformToSharedOptions(options) return r.partitions.ResolveEndpoint(region, opt) } @@ -55,119 +102,306 @@ var partitionRegexp = struct { var defaultPartitions = endpoints.Partitions{ { ID: "aws", - Defaults: endpoints.Endpoint{ - Hostname: "xray.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "xray.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "xray-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "xray.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.Aws, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "af-south-1": endpoints.Endpoint{}, - "ap-east-1": endpoints.Endpoint{}, - "ap-northeast-1": endpoints.Endpoint{}, - "ap-northeast-2": endpoints.Endpoint{}, - "ap-northeast-3": endpoints.Endpoint{}, - "ap-south-1": endpoints.Endpoint{}, - "ap-southeast-1": endpoints.Endpoint{}, - "ap-southeast-2": endpoints.Endpoint{}, - "ca-central-1": endpoints.Endpoint{}, - "eu-central-1": endpoints.Endpoint{}, - "eu-north-1": endpoints.Endpoint{}, - "eu-south-1": endpoints.Endpoint{}, - "eu-west-1": endpoints.Endpoint{}, - "eu-west-2": endpoints.Endpoint{}, - "eu-west-3": endpoints.Endpoint{}, - "fips-us-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "af-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-northeast-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ap-southeast-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "ca-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-central-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "eu-west-3", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "fips-us-east-1", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-east-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-east-2", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-east-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-east-2", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-1", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-west-2": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-west-2", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-west-2.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-west-2", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "me-south-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "sa-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-east-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-east-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-east-2.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-west-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-west-2", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-west-2", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-west-2.amazonaws.com", }, - "me-south-1": endpoints.Endpoint{}, - "sa-east-1": endpoints.Endpoint{}, - "us-east-1": endpoints.Endpoint{}, - "us-east-2": endpoints.Endpoint{}, - "us-west-1": endpoints.Endpoint{}, - "us-west-2": endpoints.Endpoint{}, }, }, { ID: "aws-cn", - Defaults: endpoints.Endpoint{ - Hostname: "xray.{region}.amazonaws.com.cn", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "xray.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "xray-fips.{region}.amazonwebservices.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "xray.{region}.amazonaws.com.cn", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsCn, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "cn-north-1": endpoints.Endpoint{}, - "cn-northwest-1": endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-north-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "cn-northwest-1", + }: endpoints.Endpoint{}, }, }, { ID: "aws-iso", - Defaults: endpoints.Endpoint{ - Hostname: "xray.{region}.c2s.ic.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "xray.{region}.c2s.ic.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIso, IsRegionalized: true, }, { ID: "aws-iso-b", - Defaults: endpoints.Endpoint{ - Hostname: "xray.{region}.sc2s.sgov.gov", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: 0, + }: { + Hostname: "xray.{region}.sc2s.sgov.gov", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsIsoB, IsRegionalized: true, }, { ID: "aws-us-gov", - Defaults: endpoints.Endpoint{ - Hostname: "xray.{region}.amazonaws.com", - Protocols: []string{"https"}, - SignatureVersions: []string{"v4"}, + Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{ + { + Variant: endpoints.DualStackVariant, + }: { + Hostname: "xray.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: endpoints.FIPSVariant | endpoints.DualStackVariant, + }: { + Hostname: "xray-fips.{region}.api.aws", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, + { + Variant: 0, + }: { + Hostname: "xray.{region}.amazonaws.com", + Protocols: []string{"https"}, + SignatureVersions: []string{"v4"}, + }, }, RegionRegex: partitionRegexp.AwsUsGov, IsRegionalized: true, Endpoints: endpoints.Endpoints{ - "fips-us-gov-east-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-east-1", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-gov-east-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-east-1", }, + Deprecated: aws.TrueTernary, }, - "fips-us-gov-west-1": endpoints.Endpoint{ + endpoints.EndpointKey{ + Region: "fips-us-gov-west-1", + }: endpoints.Endpoint{ Hostname: "xray-fips.us-gov-west-1.amazonaws.com", CredentialScope: endpoints.CredentialScope{ Region: "us-gov-west-1", }, + Deprecated: aws.TrueTernary, + }, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-east-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-gov-east-1.amazonaws.com", + }, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + }: endpoints.Endpoint{}, + endpoints.EndpointKey{ + Region: "us-gov-west-1", + Variant: endpoints.FIPSVariant, + }: { + Hostname: "xray-fips.us-gov-west-1.amazonaws.com", }, - "us-gov-east-1": endpoints.Endpoint{}, - "us-gov-west-1": endpoints.Endpoint{}, }, }, }